【发布时间】:2009-08-10 18:29:30
【问题描述】:
如果我有 2 个Buttons、A 和B,是否可以创建一个Style 和一个Trigger,这样当用户将鼠标悬停在Button B 上时,会导致@987654327 @的Style要改变吗?我试过使用SourceName 和TargetName,但遇到编译器错误。这是我正在玩弄的 XAML - 我想让Button A 的内容在Button B 被鼠标悬停时加粗:
<Window x:Class="WpfApplication1.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window4" Height="300" Width="300">
<Window.Resources>
<Style x:Key="BoldWhenOver" TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<Button Name="btnA" Content="A" Style="{StaticResource BoldWhenOver}" />
<Button Name="btnB" Content="B" />
</StackPanel>
【问题讨论】:
标签: wpf xaml triggers uielement