WPF MultiDataTrigger不起作用

沙美

所以我有多边形:

<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>

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

埃利·阿尔贝尔(Eli Arbel)

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章