相关疑难解决方法(0)

WPF:将bool值显示为"是"/"否"

我有一个bool值,我需要在TextBlock中显示为"是"或"否".我试图用StringFormat做这个,但我的StringFormat被忽略,TextBlock显示"True"或"False".

<TextBlock Text="{Binding Path=MyBoolValue, StringFormat='{}{0:Yes;;No}'}" />
Run Code Online (Sandbox Code Playgroud)

我的语法有问题,还是不支持这种类型的StringFormat?

我知道我可以使用ValueConverter来实现这一目标,但StringFormat解决方案看起来更优雅(如果有效).

data-binding wpf formatting xaml

42
推荐指数
5
解决办法
4万
查看次数

标签 统计

data-binding ×1

formatting ×1

wpf ×1

xaml ×1