2

我创建了简单StateTrigger的绑定到FrameworkElement Width属性。存在三个依赖属性MinValueMaxValueElement。它们的类型是doubledouble并且FrameworkElement相应地。

而且我注意到,根据绑定顺序,它可能会或可能不会起作用。

这工作正常。

<local:ElementWidthTrigger MaxValue="1000"
                           MinValue="800"
                           Element="{Binding ElementName=LayoutRoot}" />

这不是。

<local:ElementWidthTrigger Element="{Binding ElementName=LayoutRoot}"
                           MaxValue="1000"
                           MinValue="800" />

请注意,这两个示例的唯一区别是Element属性绑定顺序。

ElementWidthTrigger每个依赖属性都有属性更改回调。当Element在最顶端时,无论如何都不会调用回调。

x:Bind无论使用什么顺序都可以解决这个问题,但仍然存在一个问题。谁能解释为什么Element属性无法根据绑定顺序绑定?

在 Windows 10 1803 版本 17134.320 上运行。

工作示例项目可以在这里找到。

4

2 回答 2

3

感谢您报告此问题并提供可靠的重现项目 - 这是一个平台错误。我已将其记录在我们的数据库中并分配给正确的团队。再次感谢!

于 2018-10-13T05:14:33.597 回答
2

哇,这是一个谜!虽然我无法找出问题的原因,但它确实看起来像是 UWP 中的一个错误。我注意到,将 a 添加x:Name到其中一个的简单行为VisualStates甚至可以使ElementName-first 订单按预期工作:

<VisualState x:Name="Test">
    <VisualState.StateTriggers>
        <local:ElementWidthTrigger Element="{Binding ElementName=LayoutRoot}"
                                   MaxValue="1000"
                                   MinValue="800" />
    </VisualState.StateTriggers>

    <VisualState.Setters>
        <Setter Target="Rectangle.Fill" Value="Blue" />
    </VisualState.Setters>
</VisualState>

如果 UWP 团队的某个人看到了这一点并提供了帮助,那就太好了,因为它可能需要深入了解内部情况才能了解正在发生的事情。

于 2018-10-09T12:03:08.343 回答