shufflecode / DataBindingDemo

Small WPF Demo with DataBindings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small WPF Demo project to show databindin in userControls

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>
Visualisation of the different Datacontexts :

Datacontext

About

Small WPF Demo with DataBindings


Languages

Language:C# 100.0%