Michael Hedgpeth
Michael Hedgpeth

Reputation: 7862

How to bind the Selected Item to a Model with the 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 where the parent DataContext is the above model:

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

I want to bind the CurrentElement property to the Selected Item of the Grid, similar to how I would in a ListView:

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

How would you suggest I do this?

Upvotes: 3

Views: 7025

Answers (1)

John Myczek
John Myczek

Reputation: 12256

As stated on the Infragistics forum, the XamDataGrid exposes an IsSynchronizedWithCurrentItem property. To take advantage of this, you need a ListCollectionView of your ObservableCollection. Something like this:

public ListCollectionView ElementsView {get;set;}

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

Then bind your XamDataGrid to ElementsView.

Upvotes: 4

Related Questions