[英]How to set multiple conditions depending on Binding and Property in XAML?
so I have a simple DataGrid. 所以我有一个简单的DataGrid。 I have 4 colors to be displayed for the rows. 我有4种颜色要显示的行。
Implementing 1. and 2. is simple, just set the default to Green and onHovering to DarkGreen. 实现1.和2.很简单,只需将默认值设置为Green,将onHovering设置为DarkGreen。
For 3. I use a simple DataTrigger. 对于3。我使用一个简单的DataTrigger。
<DataTrigger Binding="{Binding Time}" Value="{x:Null}">
<Setter Property="Background" Value="{DynamicResource RedBackgroundColor}"/>
</DataTrigger>
But how would I implement 4.? 但是我将如何实施4.? I would've used a Multidatatrigger like 我会用像
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Time}" Value="{x:Null}"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Background" Value="{DynamicResource RedBackground}"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
But the code above won't work. 但是上面的代码不起作用。 Seems like this line is causing problems when using Property in a DataTrigger: 在DataTrigger中使用Property时,似乎此行引起问题:
Condition Property="IsMouseOver" Value="True" 条件Property =“ IsMouseOver” Value =“ True”
So I figured out how to possibly solve my question. 所以我想出了如何解决我的问题。
I thought it was some kind of referencing problem, as using a DataTrigger may not know about the Properties of a Control like a Trigger would, so I had to reference it differently. 我认为这是某种引用问题,因为使用DataTrigger可能不像触发器那样了解控件的属性,因此我不得不以不同的方式引用它。
That's what I came up with and it is working as intended now: 这就是我想出的,它现在可以按预期工作:
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsMouseOver}" Value="True"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.