Shows, how a reusable usercontrol can be written with dependency propertys an manual setting of datacontext
- UserControl with databindings into viewmodel class
<controls:TableView Table="{Binding Table2}"/>
- in the UserControl, the databinding leads to propertys of the viewmodel
<UserControl x:Class="DataBindingDemo.Controls.TableView">
<!--Datacontext is derived from the UI in which the control is embedded
therfore the binding leads to a property in MainWindow-->
<Grid>
<StackPanel>
<Label Content="{Binding DemoTitle}"
Cursor="Hand"/>
</StackPanel>
<!--Datacontext is set in code behind -->
<StackPanel Name="LayoutRoot">
<TextBlock Text="{Binding Table.Name}" />
<DataGrid ItemsSource="{Binding Table.Entries}"/>
</StackPanel>
</Grid>
</UserControl>