WPF set border background in trigger

后端 未结 1 895
我寻月下人不归
我寻月下人不归 2020-12-29 05:28

I need to create a trigger, that will change Border background property, when MouseEnter occurred. I did the follow:



        
相关标签:
1条回答
  • 2020-12-29 06:17

    Common mistake. You have set the Border.Background property directly which will always override the value set by your trigger. (Locally set values have a very high precedence, style has a pretty low precedence.)

    Instead, you should move your "normal" background into the Style like so:

    <Border>
        <Border.Style>
            <Style TargetType="Border">
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush>
                            <LinearGradientBrush.GradientStops>
                                <GradientStop Color="Aquamarine" Offset="0"/>
                            </LinearGradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <!-- the trigger you showed -->
                </Style.Triggers>
            </Style>
        </Border.Style>
    </Border>
    
    0 讨论(0)
提交回复
热议问题