为什么在 UWP 的样式设置器中 {x:Null} 不再是有效值? [英] Why is {x:Null} no longer a valid value in a Style Setter in UWP?
问题描述
跟进
我知道将值设置为 {x:Null}
是有效的.如果您直接设置 <ListView Transitions="{x:Null}"/>
,那么它可以正常工作......正如预期的那样.
那么……样式设置器发生了什么?...仔细解释一下,微软?至少有替代方法吗?
这确实是一种奇怪的行为,总体而言,因为正如您所解释的,直接设置为 null 有效,而使用样式则无效.我发现的唯一选择就是设置一个清晰的 transitioncollection:
<Style x:Key="MyList" TargetType="ListView"><Setter Property="Transitions" ><Setter.Value><TransitionCollection></TransitionCollection></Setter.Value></Setter><Setter Property="DataContext" Value="{x:Null}"/></风格>
我将 DataContext 的示例设置为可以设置为 null,它说同样的错误但编译和工作.
我知道这不是最好的解决方案,但有一个清晰的过渡集合是一种解决方法.
A follow up to this question, why is {x:Null}
no longer a valid option for Setter.Value
?
Put this code in a resource dictionary in your UWP app:
<Style x:Key="MyList"
TargetType="ListView">
<Setter Property="Transitions"
Value="{x:Null}"/>
</Style>
And use it in any ListView
:
<ListView Style="{StaticResource MyList}"/>
Your app will crash. A nasty crash as well, the kind that takes down the app without breaking properly in your debugger.
Also, the designer complains with a Catastrophic failure:
I know that setting values to {x:Null}
is valid. If you set the <ListView Transitions="{x:Null}"/>
directly, then it works fine... as expected.
So... what happened with style setters? ... Care to explain, Microsoft? Is there at least an alternate method?
It is really a weird behavior and overall because as you explained setting directly to null works and with the style does not. The only alternative I found is just set a clear transitioncollection:
<Page.Resources>
<Style x:Key="MyList" TargetType="ListView">
<Setter Property="Transitions" >
<Setter.Value>
<TransitionCollection></TransitionCollection>
</Setter.Value>
</Setter>
<Setter Property="DataContext" Value="{x:Null}"/>
</Style>
I set the example of the DataContext that can be set to null, it says the same error but compiles and works.
I know it is not the best solution but it is a workaround to have a clear transitioncollection.
这篇关于为什么在 UWP 的样式设置器中 {x:Null} 不再是有效值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!