How to access parent's DataContext from a UserControl

Viewed 27710

I need to access the container's DataContext from a UserControl (a grid containing textboxes and a listbox: I need to insert items in this list box) that I created in WPF: which is the best way to do it?

I was thinking to pass the DataContext as parameter to user control but think there is a cleaner way to do it.

5 Answers

In this case, UserControl will get DataContext windows

<Window>
    <local:MyUserControl DataContext="{Binding}"/>
</Window>
Related