views:

1471

answers:

1

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?

+2  A: 

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.

John Myczek
Putting the ListCollectionView in the ViewModel was the missing link. I didn't want to put a WPF reference to my underlying model. Thanks a lot.
Michael Hedgpeth