WPF MultiDataTrigger 不工作

WPF MultiDataTrigger not working

所以我有多边形:

<Polygon Points="1.875,0.875 2.75,13.875 18.875,11 16.625,-3.375 1.875,0.875 "
             Style="{ StaticResource BlockView}"
             Name="KEY_1"
             Canvas.Left="35"
             Canvas.Top="211"
             attachedproperty:UtilityFunctions.IsDualModeActive="{Binding  GetDevice.SelectedProfile.IsDualMode,Mode=TwoWay}" />

我希望根据 IsMouseOver 属性 和附加的 属性 的值更改多边形的笔画,如下所示:

public static readonly DependencyProperty IsDualModeActiveProperty = DependencyProperty.RegisterAttached(
                                                                        "IsDualModeActive",
                                                                        typeof(Boolean),
                                                                        typeof(UtilityFunctions)
        );
    public static void SetIsDualModeActive(UIElement element, Boolean value)
    {
        element.SetValue(IsDualModeActiveProperty, value);
    }
    public static Boolean GetIsDualModeActive(UIElement element)
    {
        return (Boolean)element.GetValue(IsDualModeActiveProperty);
    }

附加的 属性 绑定到我的 ViewModel 中的 属性,如您在多边形代码中所见。 然后我在样式资源中定义了这个触发器:

 <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver }"
                                   Value="True" />
                        <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsDualModeActive }"
                                   Value="False" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation  Storyboard.TargetProperty="Stroke.Color"
                                                 To="#73BB00"
                                                 Duration="{StaticResource controlTransitionEnterDuration}" />
                            </Storyboard>
                        </BeginStoryboard>
                    </MultiDataTrigger.EnterActions>
                    <MultiDataTrigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetProperty="Stroke.Color"
                                                Duration="{StaticResource controlTransitionEnterDuration}" />
                            </Storyboard>
                        </BeginStoryboard>
                    </MultiDataTrigger.ExitActions>
                    <Setter Property="Opacity" Value="3" />
                </MultiDataTrigger>

问题是我检查了鼠标悬停和附加的值属性,它们满足触发条件但多边形的笔划没有改变。 我在这里错过了什么吗? 谢谢

当您使用 属性 路径指定附加的 属性 时,您还必须使用方括号语法指定它定义的类型:

<Condition Binding="{Binding RelativeSource={RelativeSource Self},
     Path=(attachedproperty:UtilityFunctions.IsDualModeActive)}" Value="False" />