【发布时间】:2010-07-28 09:26:14
【问题描述】:
我想创建一个带有圆角右上角和右下角的平面按钮。此按钮需要在单击和鼠标悬停时更改背景。
目前我的标记如下所示:
<Border x:Name="MyButton" Height="25" Margin="0,5,0,0" CornerRadius="0 5 5 0" BorderThickness="1" BorderBrush="Gray" Style="{StaticResource myStyle1}">
<StackPanel Orientation="Horizontal" Margin="8,0,0,0">
<Image Source="image.jpg" Height="20"/>
<TextBlock Text="My Button"/> <!-- Could also be a label if needs to be. -->
</StackPanel>
</Border>
<Style x:Key="myStyle1" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource MainContentForegroundColor}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
鼠标悬停在触发器上效果很好,但我无法让点击触发器工作...我尝试过IsKeyboardFocusWithin 和IsFocused,但没有成功。
【问题讨论】:
标签: wpf templates focus styles