c#wpf,属性的绑定值取决于bool值
对不起,我的英语不好。我想根据对象的布尔值绑定c#wpf,属性的绑定值取决于bool值,c#,wpf,C#,Wpf,对不起,我的英语不好。我想根据对象的布尔值绑定ListBoxItem的BorderBrush。 我有一个目录类,它有IsForCopy和IsCuttedbool道具。 因此,如果IsForCopy为真,则BorderBrush=红色,如果IsCutted为真,则BorderBrush=蓝色。我该怎么做 ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}" BasedOn
ListBoxItem
的BorderBrush
。
我有一个目录
类,它有IsForCopy
和IsCutted
bool道具。
因此,如果IsForCopy
为真,则BorderBrush
=红色,如果IsCutted
为真,则BorderBrush
=蓝色。我该怎么做
ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseDoubleClick" Handler="SecondListBoxItem_MouseDoubleClick"/>
<Setter Property="BorderBrush" Value="What do I should type there?"></Setter>
</Style>
</ListBox.ItemContainerStyle>
ListBox.ItemContainerStyle>
您需要一个实现IValueConverter的类。然后在convert方法中,您可以指定如何以任何方式将布尔映射到笔刷。每个绑定都有一个converter属性,您可以将该属性设置为实现IValueConverter的类