c# - 如何使用 Infragistics XamDataGrid 将所选项目绑定(bind)到模型?

标签 c# wpf mvvm infragistics

我有以下模型:

public class Model : INotifyPropertyChanged 
{
  public ObservableCollection<ViewElement> Elements { get; set; }

  public ViewElement CurrentElement { get; set; }
}

以及以下网格,其中父 DataContext 是上述模型:

<dg:XamDataGrid DataSource="{Binding Path=Elements}" />

我想将 CurrentElement 属性绑定(bind)到网格的选定项,类似于我在 ListView 中的做法:

    <ListView x:Name="playbackSteps"
          ItemsSource="{Binding Path=Elements}"
          SelectedItem="{Binding Path=CurrentElement}" />

你会如何建议我这样做?

最佳答案

Infragistics forum 中所述中,XamDataGrid 公开了一个 IsSynchronizedWithCurrentItem 属性。要利用这一点,您需要一个 ListCollectionView你的 ObservableCollection。像这样:

public ListCollectionView ElementsView {get;set;}

// In the constructor:
this.ElementsView = new ListCollectionView(Elements);

然后将您的 XamDataGrid 绑定(bind)到 ElementsView。

关于c# - 如何使用 Infragistics XamDataGrid 将所选项目绑定(bind)到模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/785607/

相关文章:

C#:如何获取某个文件的图标?

c# - 用户控件阻止底层用户控件接收拖放内容

wpf - 如何动态地将 ViewModel 连接到其适当的 View?

entity-framework - Windows Phone 8 MVVM数据库优先(如EF)

c# - 如何在RDLC中格式化日期时间以本地日期时间格式显示?

c# - 如何在业务层实现审计

c# - 如何通过一次调用使用 mongodb C# 驱动程序添加嵌套元素或更新属性

c# - Xelement - 获取元素

c# - ScrollViewer.ScrollToBottom 未完全滚动

c# - wpf richtextbox 中没有上标