WPF Data Binding Cheat Sheet

So as I was scouring the web for the best way to access a parent data context from within an ItemsControl Item Template. I found this fantastic cheat sheet for WPF binding. Of course it didn’t have exactly what I was looking for but it is a great reference.

<Button 
    Content="Move Up"
    Command="{Binding   RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, 
                        Path=DataContext.MyCommand}"
    CommandParameter="{Binding}"
    />

The above XAML lives within a Item Template and accesses the DataContext from the parent element.

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