I have a ListView that is configured as a GridView. It is databound to a DataTable and displays several columns of ints. I'd like to display the maximum value in each column in the bold font.
我有一个配置为GridView的ListView。它被数据绑定到DataTable并显示几列int。我想以粗体显示每列中的最大值。
To do this, I have a MultiBinding on the FontWeight of each cell. It is easy enough to pass the cell value to the MultiBinding converter. But how do I pass all of the items in that column to the converter? Or is there a way to pass the the entire databound DataTable to the converter?
为此,我在每个单元格的FontWeight上有一个MultiBinding。将单元格值传递给MultiBinding转换器很容易。但是,如何将该列中的所有项目传递给转换器?或者有没有办法将整个数据绑定DataTable传递给转换器?
1 个解决方案
#1
One way you could do it is expose your DataTable in the view itself as a property. Then with your converter bind to the DataTable and set ConverterParameter to the name of the column.
您可以采用的一种方法是将视图中的DataTable作为属性公开。然后使用转换器绑定到DataTable并将ConverterParameter设置为列的名称。
... FontWeight="{Binding Converter={StaticResource MaxValueConverter}, ElementName=MyControl, Path=MyDataTable, ConverterParameter='ColumnName'}"/>
Unfortunately, you can't do this..
不幸的是,你不能这样做..
... FontWeight="{Binding Converter={StaticResource MaxValueConverter}, Path={Binding}}"/>
..but it would make binding to the DataContext much easier.
..但它会更容易绑定到DataContext。
#1
One way you could do it is expose your DataTable in the view itself as a property. Then with your converter bind to the DataTable and set ConverterParameter to the name of the column.
您可以采用的一种方法是将视图中的DataTable作为属性公开。然后使用转换器绑定到DataTable并将ConverterParameter设置为列的名称。
... FontWeight="{Binding Converter={StaticResource MaxValueConverter}, ElementName=MyControl, Path=MyDataTable, ConverterParameter='ColumnName'}"/>
Unfortunately, you can't do this..
不幸的是,你不能这样做..
... FontWeight="{Binding Converter={StaticResource MaxValueConverter}, Path={Binding}}"/>
..but it would make binding to the DataContext much easier.
..但它会更容易绑定到DataContext。