First model:
public class FirstModel
{
public string HelloWorld { get; set; }
public FirstModel()
{
HelloWorld = "First model";
}
}
Second model:
public class SecondModel
{
public string HelloWorld { get; set; }
public SecondModel()
{
HelloWorld = "Second model";
}
}
XAML:
<Window x:Class="TwoDataContext.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:twoDataContext="clr-namespace:TwoDataContext"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<twoDataContext:FirstModel x:Key="FirstModel" />
<twoDataContext:SecondModel x:Key="SecondModel" />
</Grid.Resources>
<TextBox DataContext = "{StaticResource FirstModel}" HorizontalAlignment="Left" Height="23" Margin="178,64,0,0" TextWrapping="Wrap" Text="{Binding HelloWorld}" VerticalAlignment="Top" Width="120"/>
<TextBox DataContext = "{StaticResource SecondModel}" HorizontalAlignment="Left" Height="23" Margin="178,120,0,0" TextWrapping="Wrap" Text="{Binding HelloWorld}" VerticalAlignment="Top" Width="120"/>
</Grid>
</Window>
Example you can download from here.