【发布时间】:2014-08-21 00:13:59
【问题描述】:
我有一个数据网格,我希望能够使用 XAML 检测我的列是否显示 0,并且在这种情况下将零替换为“-”。
这是我的数据网格:
<DataGrid Style="{DynamicResource StyleDataGrid}" ItemsSource="{Binding Path=_Data, UpdateSourceTrigger=PropertyChanged}" Margin="10,54,10,10" Name="dataGridView1" >
<DataGrid.Columns>
<DataGridTextColumn Width="35" Binding="{Binding Path=Object.MyValue}" SortMemberPath="Object.MyValue" Header="" IsReadOnly="true">
<DataGridTextColumn.CellStyle>
<Style BasedOn="{StaticResource {x:Type DataGridCell}}" TargetType="DataGridCell">
<Setter Property="Foreground" Value="{Binding BrushTroisPts}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=TextBlock.Text, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TextBlock}}}" Value="0">
<Setter Property="TextBlock.Text" Value="-"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
但这不起作用,我怎样才能使它起作用?
谢谢
【问题讨论】:
标签: wpf xaml triggers datatrigger