WPF-鼠标过度效果未发生

时间:2017-12-21 02:07:14

标签: c# wpf xaml

我在WPF中创建了一组按钮。我在按钮上添加了两个触发器,MouseOver和IsPressed。但是,只有IsPressed触发器正在工作,但不是MouseOver效果。我希望能够用鼠标光标突出显示该按钮,然后它会变为不同的颜色。我错过了什么?

XAML:

<Setter Property="Template">
        <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
        <Border x:Name="Border" >
     <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                   </Border>
                 <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver" Value="True">

              <Setter Property="Background" Value="DarkGoldenrod"/>
                            </Trigger>

           <Trigger Property="IsPressed" Value="True">
     <Setter TargetName="Border" Property="BorderThickness" Value="10,10,0,0"/>

              </Trigger>
                 </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
            </Setter>

编辑:

<Style.Triggers>
                    <Trigger Property="IsPressed" Value="True">

                        <Setter Property="BorderThickness" Value="10,10,0,0">

                        </Setter>
                        <Setter Property="Opacity" Value="0.2"/>

                    </Trigger>

                </Style.Triggers>

1 个答案:

答案 0 :(得分:1)

你的DarkGoldenrod触发器中缺少TargetName =“Border”。