繁体   English   中英

c#wpf,属性的绑定值取决于布尔值

[英]c# wpf, binding value of property depending on the bool value

对不起,我的英语不好。 我想根据对象的布尔值绑定ListBoxItemBorderBrush 我有一个Directory类,它具有IsForCopyIsCutted bool道具。 因此,如果IsForCopy为true,则BorderBrush =红色,如果IsCutted为true,则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>

您需要一个实现IValueConverter的类。 然后,在convert方法中,您可以指定如何将布尔值映射到笔刷。 每个绑定都有一个转换器属性,您可以将其设置为实现IValueConverter的此类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM