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

3

我有以下模型:

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}" />

您认为我应该如何做到这一点?


这篇文章也在 infragistics 论坛上发布了:http://news.infragistics.com/forums/p/24777/90741.aspx#90741 - Michael Hedgpeth
1个回答

4

如在Infragistics论坛中所述,XamDataGrid公开了一个IsSynchronizedWithCurrentItem属性。要利用此功能,您需要使用ObservableCollection的ListCollectionView。类似于这样:

public ListCollectionView ElementsView {get;set;}

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

然后将XamDataGrid绑定到ElementsView。

将ListCollectionView放在ViewModel中是缺失的一环。我不想将WPF引用到我的基础模型中。非常感谢。 - Michael Hedgpeth

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接