如何在属性不为null时在WPF中触发操作?当为null时,这是一个有效的解决方案:
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="{x:Null}">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
Run Code Online (Sandbox Code Playgroud)
我知道你不能"扭转"这种情况并做你需要的事情,但想知道
Tho*_*que 10
不幸的是,你做不到.但实际上没有必要:您只需要在样式设置器中指定值不为空的背景,而不是在触发器中:
<Style.Setters>
<!-- Background when value is not null -->
<Setter Property="Background" Value="Blue" />
</Style.Setters>
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="{x:Null}">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
Run Code Online (Sandbox Code Playgroud)
您可以使用Expression Blend附带的Microsoft.Expression.Interactions.dll中的DataTrigger
类.
代码示例:
<i:Interaction.Triggers>
<ie:DataTrigger Binding="{Binding YourProperty}" Value="{x:Null}" Comparison="NotEqual">
<ie:ChangePropertyAction PropertyName="YourTargetPropertyName" Value="{Binding YourValue}"/>
</ie:DataTrigger>
</i:Interaction.Triggers>
Run Code Online (Sandbox Code Playgroud)
使用这种方法,你可以触发打击GreaterThan
和LessThan
太.要使用此代码,您应该引用两个dll:
System.Windows.Interactivity.dll
Microsoft.Expression.Interactions.dll
并添加相应的命名空间:
Run Code Online (Sandbox Code Playgroud)xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ie="http://schemas.microsoft.com/expression/2010/interactions"
归档时间: |
|
查看次数: |
15093 次 |
最近记录: |