我想为我的TabControl设置一个MultiDataTrigger。当标签悬停时,它应该改变颜色。但是如果选中Tab则不行。我尝试了一个MultiDataTrigger。但它似乎没有用。这是我的风格:
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border Name="Border" BorderBrush="Black" BorderThickness="0.5,0.5,0.5,0" CornerRadius="4,4,0,0">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#fefeff" Offset="0" />
<GradientStop Color="#e7edf6" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#c5d0df" Offset="0" />
<GradientStop Color="#aab4c2" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsMouseOver}" Value="True" />
<Condition Binding="{Binding Path=IsSelected}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#dde6f2" Offset="0" />
<GradientStop Color="#c6d0de" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
有什么不对吗?
答案 0 :(得分:4)
将您的触发器更改为:
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false"/>
<Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>
根据AngelWPF's回答,DataTrigger将尝试绑定到当前的DataContext,在那里找不到与属性匹配的内容。
答案 1 :(得分:2)
DataTriggers使用DataContext
作为来源。我确信IsMouseOver
和IsSelected
不是数据上下文中的属性,它们是标签项的属性。
我建议使用正常的MultiTrigger
,其中包含正常的Trigger
Condition
。