Formatting Cell in WPF DataGrid
Say I have a DataGrid with its ItemsSource binding to a data table(whose columns are various). One column of the table is double type with several NaN values. While on the display 开发者_StackOverflow社区part, I want to format all the NaN value to blank.
What I did is to set a style to the DataGridCell like this:
<Style TargetType="DataGridCell">
<Setter Property="Content" Value="{Binding Converter={StaticResource NumberConverter}}" />
</Style>
But it doesn't work because the DataContext of the cell is DataRowView which means I cannot get which column I was at in the converter.
Any one has a good idea? Thanks a lot.
Actually, what I want to do is to convert the NaN cells to blank. So I created the DataTable and generate the DataColumn which allows DBNull. When the value is NaN in the datasource, I can set the value to DBNull.Value so that the NaN shows nothing in my DataGrid. Hope it helps if you have the same issue.
精彩评论