如何从基本样式覆盖IsMouseOver触发器上的borderbrush /背景色属性?

时间:2019-06-21 13:54:23

标签: wpf xaml

有两种不同类型的复选框,鼠标悬停时背景颜色会有所不同。我想更改IsMouseOver上“ checkboxBorder”的背景颜色。我想知道如何实现这一目标。骨架代码如下:

    <Style x:key="BaseStyle" TargetType="{x:type checkbox}">
    <setter property="Template">
    <setter.value>
           <ControlTemplate TargetType="{x:type checkbox}">
              <grid x:Name="templateRoot">
                  <border x:Name="checkBoxBorder">
                         <Grid x:Name="markGrid">
                              <Path x:Name="optionMark"/>
                         </grid>
                  </border>
              </grid>
              <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver"
                                     Value="true">
                                <Setter Property="Background"
                                        TargetName="checkBoxBorder"
                                        Value="{StaticResource blue}" />
                                <Setter Property="BorderBrush"
                                        TargetName="checkBoxBorder"
                                        Value="{StaticResource 
                   Lochmara}" />
                                <Setter Property="Fill"
                                        TargetName="TickMark"
                                        Value="{StaticResource White}" 
           />
                            </Trigger>
              </ControlTemplate.Triggers>
           </ControlTemplate>
    </setter.value>
    </setter>
    </style>

  In the below xaml style i am using the above base style on top of that i 
   need to assign different color for "checkboxborder" background property 
  on mouseover   

   <Style x:key="BaseStyle" TargetType="{x:type checkbox}" 
             BasedOn="BaseStyle">
          <style.Triggers>
                <Trigger Property="IsMouseOver"
                                 Value="true">
                            <Setter Property="Background"
                                    TargetName="checkBoxBorder"
                                    Value="{StaticResource Shimmer}" />
                            <Setter Property="BorderBrush"
                                    TargetName="checkBoxBorder"
                                    Value="{StaticResource Lochmara}" />
                            <Setter Property="Fill"
                                    TargetName="TickMark"
                                    Value="{StaticResource White}" />
                        </Trigger>
          </style.Triggers>
  </Style>

0 个答案:

没有答案