2009-04-24 104 views
3

我有以下型号:如何使用Infragistics XamDataGrid将选定项目绑定到模型?

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

    public ViewElement CurrentElement { get; set; } 
} 

及以下电网,其中母公司DataContext是上面的模型:

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

我想将CurrentElement属性绑定到网格中所选择的项目,类似于我如何在一个ListView

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

你会建议我这样做?

+0

这是交叉张贴在infragistics论坛这里:http://news.infragistics.com/forums/p/24777/90741.aspx#90741 – 2009-04-24 12:19:06

回答

3

Infragistics forum所述,XamDataGrid公开了IsSynchronizedWithCurrentItem属性。要利用此优势,您需要ObservableCollection的ListCollectionView。像这样:

public ListCollectionView ElementsView {get;set;} 

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

然后将您的XamDataGrid绑定到ElementsView。

+0

把ListCollectionView放在ViewModel是缺少的链接。我不想将WPF引用放到我的基础模型中。非常感谢。 – 2009-04-25 02:15:07

相关问题