简体   繁体   English

GridViewColumn CellTemplate 文本运行的条件可见性

[英]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 .您可以利用StringFormatTargetNullValue

<Run Text="{Binding Prop1}"></Run>
<Run Text="{Binding Prop2, StringFormat={}{{{0}}}, TargetNullValue={}}"></Run>

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

相关问题 MultiBinding a TextBlock in a StackPanel in a GridViewColumn.CellTemplate 并且文本不显示 - MultiBinding a TextBlock in a StackPanel in a GridViewColumn.CellTemplate and the Text does not show 有没有一种方法可以在运行时更改GridViewColumn的CellTemplate? - Is there a way to change CellTemplate of GridViewColumn at Runtime? 从 GridViewColumn 获取 CellTemplate 绑定 - Get CellTemplate binding from GridViewColumn 如何更改用于GridViewColumn的CellTemplate的数据模板 - How to change the Datatemplate which is used for CellTemplate of the GridViewColumn 使用celltemplate绑定集合以显示在gridview列中 - Binding a collection for display in a gridviewcolumn using celltemplate 从 GridViewColumn 或 GridViewColumn.CellTemplate 的 GridView 获取项目 - Get items from GridViewColumn or GridViewColumn.CellTemplate of GridView WPF GridViewColumn CellTemplate c#的动态更改 - WPF Dynamic change of GridViewColumn CellTemplate c# GridViewColumn Visibility属性的绑定失败 - Binding failed for a GridViewColumn Visibility property 具有TextBox的GridViewColumn.CellTemplate无法与ListView.ItemContainerStyle一起使用 - GridViewColumn.CellTemplate with TextBox not working with ListView.ItemContainerStyle 如何在GridViewColumn中绑定文本对齐方式 - How to bind text alignment in GridViewColumn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM