[英]GridViewColumn CellTemplate Conditional Visibility of Text Run
In below snippet I would like to hide the Run Text
when the second property Prop2
is null or empty.在下面的代码片段中,当第二个属性Prop2
为 null 或为空时,我想隐藏Run Text
。 What is the best way of doing this?这样做的最佳方法是什么?
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock >
<Run Text="{Binding Prop1}"></Run>
<Run Text=" {"></Run> <----- Collapse/Hide when Prop2 is null or empty
<Run Text="{Binding Prop2}"></Run><----- Collapse/Hide when Prop2 is null or empty
<Run Text="}"></Run><----- Collapse/Hide when Prop2 is null or empty
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
You can take advantage of StringFormat
and TargetNullValue
.您可以利用StringFormat
和TargetNullValue
。
<Run Text="{Binding Prop1}"></Run>
<Run Text="{Binding Prop2, StringFormat={}{{{0}}}, TargetNullValue={}}"></Run>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.