【问题标题】:WPF : Change DataTemplate of specific cell on DataGridWPF:更改 DataGrid 上特定单元格的 DataTemplate
【发布时间】:2013-09-03 08:01:50
【问题描述】:

我想创建一个这样的 DataGrid:

用户可以在运行时添加-删除列。如图所示,我必须在特定 Cells 上使用 DatePicker 和 checkbox 以及其他控件。
如何使用 WPF DataGrid 做到这一点?
我想我必须更改特定单元格的 DataTemplate 但我不知道如何
DataGrid 是否适合这种情况?

【问题讨论】:

    标签: wpf


    【解决方案1】:

    我建议将所有过滤器控件(?)放在 DataGrid 标题中“暂停”下方的行上方。你可以放任何你想要的东西。

    <Window.Resources>
        <DataTemplate x:Key="MySpecialHeaderTemplate">
            ...
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <DataGrid>
            <DataGrid.Columns>
                <DataGridTextColumn HeaderTemplate="{StaticResource MySpecialHeaderTemplate}"
                        Binding="{Binding ...}" />
                <DataGridTextColumn HeaderTemplate="{StaticResource MySpecialHeaderTemplate}"
                        Binding="{Binding ...}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    

    这并不容易,尤其是在标头中找到保存那些控件数据的 ViewModel,但这是可能的。

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 2011-06-29
      • 2014-10-27
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 2023-03-28
      相关资源
      最近更新 更多