【问题标题】:Sorting a WPF DataGrid, MVVM style对 WPF DataGrid、MVVM 样式进行排序
【发布时间】:2010-12-24 21:31:05
【问题描述】:

我正在尝试使用 WPF Toolkit DataGrid 进行排序。我的 DataGrid 的行是视图模型的实例。行的视图模型为每一列公开一个视图模型。每列都是模板化到不同用户控件的数据。这是我的 DataGrid 的列声明的样子:

<tk:DataGrid.Columns>
    <tk:DataGridTemplateColumn Header="Name" MinWidth="150" Width="150">
        <tk:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding Path=NameViewModel}"/>
            </DataTemplate>
        </tk:DataGridTemplateColumn.CellTemplate>
    </tk:DataGridTemplateColumn>
    <tk:DataGridTemplateColumn Header="Data Dependencies" MinWidth="350" Width="Auto">
        <tk:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding Path=DependenciesViewModel}"/>
            </DataTemplate>
        </tk:DataGridTemplateColumn.CellTemplate>
    </tk:DataGridTemplateColumn>
</tk:DataGrid.Columns>

Name 绑定到一个视图模型,该模型是数据模板,用户控件将名称显示为文本块。它还显示一些其他图形信息,这就是它显示在用户控件中的原因。

这样做的问题是我无法对Name 列进行排序。我希望在暴露名称视图模型的行视图模型上实现 IComparable&lt;T&gt; 可以解决问题,但它看起来并不像 WPF 数据网格在乎它实现 IComparable&lt;T&gt;

有人对如何最好地解决这个问题有任何建议吗?

【问题讨论】:

    标签: wpf datagrid mvvm wpftoolkit


    【解决方案1】:

    answer 正是我要找的。​​p>

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 2016-02-12
      • 1970-01-01
      • 2011-08-12
      • 2010-12-10
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      相关资源
      最近更新 更多