我的窗口中有一个 TabControl 。所以我为它写了一个风格,如下面的代码。
我想使用带有2个条件的第二个(multitrigger)(IsSelected = True + IsMouseOver = True),但我发现它的效果将在我评论单个触发器时显示 !!
所以我评论了multitrigger中的IsMouseOver = True条件并再次测试但是结果与之前的结果相同>> 单个触发器被评论时显示的效果
同样我将Single触发器向下放置并且Multitrigger向上然后测试它但是结果与之前的结果相同>> 效果只显示单个触发器被评论
我的代码有错吗?
在WPF中,单个触发器在具有相同条件的multiTriggers上具有优先权吗?
原因不同......
如何解决此问题?
<Style TargetType="TabControl">
<Style.Resources>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border x:Name="TabItemBorder"...........
<Border.Background>
<LinearGradientBrush x:Name="TabControlBorderLinearGradientBrush"........
<GradientStop Color="#FF999999"....
<GradientStop Color="#FF999999"....
<GradientStop Color="#FFa3a3a3"....
</LinearGradientBrush>
</Border.Background>
<ContentPresenter x:Name="ContentSite".....
</Border>
<ControlTemplate.Triggers>
&lt; - 第一单触发器 - &gt; :
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="TabItemBorder" Property="Background">
<Setter.Value>
<LinearGradientBrush......
<GradientStop Color="#FF9D6AC6".....
<GradientStop Color="#FF9D6AC6".....
<GradientStop Color="#FFA776CF".....
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
&lt; - 第二次多重触发 - &gt; :
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<!--<Condition SourceName="TabItemBorder" Property="IsMouseOver" Value="true"/>-->
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)"
To="#FFaD6AC6"....
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
To="#FFaD6AC6"....
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)"
To="#FFb776CF"....
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)"
To="#FF9D6AC6"....
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
To="#FF9D6AC6"....
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)"
To="#FFA776CF"....
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
修改
内部触发我使用此方法更改 TabItemBorder 背景:
<Setter TargetName="TabItemBorder" Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF9D6AC6" Offset="0"/>
<GradientStop Color="#FF9D6AC6" Offset="0.584"/>
<GradientStop Color="#FFA776CF" Offset="0.571"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
和 Inside MultiTrigger 我使用此方法更改 TabControlBorderLinearGradientBrush 背景:
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)"
To="#FFaD6AC6" Duration="0:0:0.2"/>
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
To="#FFaD6AC6" Duration="0:0:0.2"/>
<ColorAnimation Storyboard.TargetName="TabControlBorderLinearGradientBrush" Storyboard.TargetProperty = "(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)"
To="#FFb776CF" Duration="0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
TabControlBorderLinearGradientBrush 是 TabItemBorder背景属性的 LinearGradientBrush