WPF & MVVM: DataBinding UserControl Command to Parent DataContext

I had been struggling with figuring out how to make the my XAML databinding force the command of a user control be handled by the ViewModel of the parent window in which it is contained. In an effort to follow SRP I wanted the behavior of the ViewModel of the parent window to be more of a PageController and the ViewModel for each contained UserControl follow a more pure ViewModel pattern. I was fortunate to be in contact wtih Steven Robbins via twitter (@GrumpyDev) which lead me to discover the blog post, Wpf: Binding to parent property (RelativeSource Ancestor DataContext), by Jeffrey Knight (Twitter: @jeffreyknight).
 
You can download the sample scenario I created here.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s