I want to put a column to specify range in a wpf datagrid. For this, i am thinking to take one column with header "Range" and i want to split that into 2 columns like "Minimum" and "Maximum". Is it possible to represent data like that? If it is, what about the data binding to the datagrid means how binding will change?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you can keep you min/max parts non-resizable, then a fairly simple solution exists:
- In your objects create a property of Tuple type or whatever type will represent your min/max structure.
- Add a templated column to your grid as follows (sample bindings should work with the Tuple I didn't try it though):
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Min/Max">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Item1}" />
<TextBlock Grid.Column="1" Text="{Binding Item2}" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Bind your grid to the data as normal