我有以下模型:
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/