22

我从一些例子中看到可以组合这种触发器:

<Trigger Property="IsMouseOver" Value="True">

使用这种数据触发器:

<DataTrigger Binding="{Binding IsHighlightable}" Value="True" />

通过使用这样的 MultiDataTrigger:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
        <Condition Binding="{Binding IsHighlightable}" Value="True" />
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.Setters>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="#BF6DBDD1"/>
        <Setter Property="Background" Value="{StaticResource SelectedItemBackgroundBrush}"/>
    </MultiDataTrigger.Setters>
</MultiDataTrigger>

但是,这不适用于附加属性。此触发器有效:

<Trigger Property="UI:TreeViewHelper.IsMouseDirectlyOverItem" Value="True">

但这不起作用:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=UI:TreeViewHelper.IsMouseDirectlyOverItem}" Value="True"/>
        <Condition Binding="{Binding IsHighlightable}" Value="True" />
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.Setters>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="#BF6DBDD1"/>
        <Setter Property="Background" Value="{StaticResource SelectedItemBackgroundBrush}"/>
    </MultiDataTrigger.Setters>
</MultiDataTrigger>

有没有办法让触发器在 MultiDataTrigger 中正常工作?IsMouseDirectlyOverItem 属性取自这里http://blogs.msdn.com/b/mikehillberg/archive/2006/09/21/mytreeviewhelperismousedirectlyoveritem.aspx

谢谢

4

2 回答 2

8

附加属性的语法不同:

Path=(UI:TreeViewHelper.IsMouseDirectlyOverItem)
于 2012-07-10T18:06:00.613 回答
6
<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding IsHighlightable}" Value="True"/>
        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.Setters>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="#BF6DBDD1"/>
        <Setter Property="Background" Value="{StaticResource SelectedItemBackgroundBrush}"/>
    </MultiDataTrigger.Setters>
</MultiDataTrigger>
于 2015-12-02T09:19:46.797 回答