Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Infragistics XamDataGrid将所选项目绑定到模型?_C#_Wpf_Mvvm_Infragistics - Fatal编程技术网

C# 如何使用Infragistics XamDataGrid将所选项目绑定到模型?

C# 如何使用Infragistics XamDataGrid将所选项目绑定到模型?,c#,wpf,mvvm,infragistics,C#,Wpf,Mvvm,Infragistics,我有以下型号: public class Model : INotifyPropertyChanged { public ObservableCollection<ViewElement> Elements { get; set; } public ViewElement CurrentElement { get; set; } } 我想将CurrentElement属性绑定到网格的选定项,类似于在列表视图中的绑定方式: <ListView x:Name=

我有以下型号:

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

  public ViewElement CurrentElement { get; set; }
}
我想将
CurrentElement
属性绑定到网格的选定项,类似于在
列表视图中的绑定方式:

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

您建议我如何执行此操作?

如中所述,XamDataGrid公开IsSynchronizedWithCurrentItem属性。要利用这一点,您需要对您的可观察收集进行一次分析。大概是这样的:

public ListCollectionView ElementsView {get;set;}

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

然后将XamDataGrid绑定到ElementsView。

这是在infragistics论坛中交叉发布的:将ListCollectionView放到ViewModel中是缺少的链接。我不想把WPF引用放在我的底层模型上。谢谢。
public ListCollectionView ElementsView {get;set;}

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