Wpf DataGrid Column splitting

戏子无情 提交于 2019-12-14 03:59:52

问题


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:

  1. In your objects create a property of Tuple type or whatever type will represent your min/max structure.
  2. 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



来源:https://stackoverflow.com/questions/8090974/wpf-datagrid-column-splitting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!