How to bind selected item to model using Infragistics XamDataGrid?

I have the following model:

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

  public ViewElement CurrentElement { get; set; }
}

And the following grid, in which the parent DataContextis the above model:

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

I want to bind a property CurrentElementto a selected grid element, similar to how I would in ListView:

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

How do you suggest me to do this?

+3
source share
1 answer

As indicated on the Infragistics forum , XamDataGrid provides the IsSynchronizedWithCurrentItem property. To take advantage of this, you will need a ListCollectionView of your ObservableCollection. Something like that:

public ListCollectionView ElementsView {get;set;}

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

XamDataGrid View.

+4

Source: https://habr.com/ru/post/1707032/


All Articles