How can I bind to my viewmodel from a RowDetailsTemplate

2 posts, 0 answers
  1. Jeramy
    Jeramy avatar
    12 posts
    Member since:
    Sep 2015

    Posted 14 Oct 2015 Link to this post

    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.

  2. Jeramy
    Jeramy avatar
    12 posts
    Member since:
    Sep 2015

    Posted 14 Oct 2015 in reply to Jeramy Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top