This is a migrated thread and some comments may be shown as answers.

How can I bind to my viewmodel from a RowDetailsTemplate

1 Answer 226 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeramy
Top achievements
Rank 1
Jeramy asked on 14 Oct 2015, 05:34 PM

I have a RadGridView bound to a collection within my ViewModel. That RadGridView specifies a RowDetailsTemplate. The RowDetailsTemplate is another XAML file. From the RowDetailsTemplate XAML file I can bind to members of the collection type, but cannot bind to members of the original ViewModel.

How can this be achieved?

I've tried setting the DataContext of the particular control to the ViewModel I want to bind to, but this does not work. Any help would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Jeramy
Top achievements
Rank 1
answered on 14 Oct 2015, 05:44 PM

I figured it out! 

ItemsSource="{Binding DataContext.PropertyName, RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type namespace:ParentView}}}"

 Where PropertyName is the name of the property you want to bind to, namespace is the XAML defined namespace for the parent view, and ParentView is the name of the view who's data context is the viewmodel that owns the property.

Cheers.

Tags
GridView
Asked by
Jeramy
Top achievements
Rank 1
Answers by
Jeramy
Top achievements
Rank 1
Share this question
or