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);