The DataContext
is a special field that works by setting the default binding target of an element and all of its sub-elements. So for example, you can bind to sub-properties of your DataContext by just specifying a path like so:
<StackPanel DataContext="{DynamicResource selectedBook}">
<TextBlock Text="{Binding Path=Title}" />
<TextBlock Text="{Binding Path=Author}" />
</StackPanel>
Of course, to get the DataContext from code, just access the DataContext
property and cast it to whatever type you need:
MyClass context = (MyClass)this.DataContext;
....