2009-04-24 59 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

相關問題