Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WPF数据网格中格式化单元格_Wpf_Datagrid_Cell Formatting - Fatal编程技术网

在WPF数据网格中格式化单元格

在WPF数据网格中格式化单元格,wpf,datagrid,cell-formatting,Wpf,Datagrid,Cell Formatting,假设我有一个DataGrid,它的ItemsSource绑定到一个数据表(其列是不同的)。该表的一列是具有多个NaN值的双精度类型。在显示部分,我想将所有NaN值格式化为空白 我所做的是设置DataGridCell的样式,如下所示: <Style TargetType="DataGridCell"> <Setter Property="Content" Value="{Binding Converter={StaticResource NumberConverter}}

假设我有一个DataGrid,它的ItemsSource绑定到一个数据表(其列是不同的)。该表的一列是具有多个NaN值的双精度类型。在显示部分,我想将所有NaN值格式化为空白

我所做的是设置DataGridCell的样式,如下所示:

<Style TargetType="DataGridCell">
    <Setter Property="Content" Value="{Binding Converter={StaticResource NumberConverter}}" />
</Style>

但它不起作用,因为单元格的DataContext是DataRowView,这意味着我无法获取转换器中的列

有人有好主意吗?
非常感谢。

实际上,我想做的是将NaN单元格转换为空白。因此,我创建了DataTable并生成了允许DBNull的DataColumn。当数据源中的值为NaN时,我可以将该值设置为DBNull.value,以便NaN在我的DataGrid中不显示任何内容。如果您有同样的问题,希望它能帮助您。

您可以使用XAML中的
ResourceDictionary
来定义
NumberConverter
,而不需要每个
DataGridCell
的实例。您是对的,我只想展示我正在做的更多细节;但实际上,这并不是解决我问题的办法。我试图创建一个具有显式运算符double的DoubleWrpper类;然后,我为我的新类创建列,作为datatable中的列之一。我不能以这种方式更进一步,因为列将按字符串排序,而不是按double排序。然后我尝试实现ICompare接口,但仍然没有效果。