I have a Class:
public class Person {
public string Name { set; get; }
}
And i instantiate 2 persons from that class:
Person person1 = new Person() { Name="Test1" };
Person person2 = new Person() { Name="Test2" };
And in my Window.xaml i have two textboxes that I want to bind with the two person objects
<Grid>
<TextBox />
</Grid>
<Grid>
<TextBox/>
</Grid>
But I am new in WPF and don't know how to do.
I tried
<Grid DataContext="{Binding person1}">
<TextBox Text="Binding Name"/>
</Grid>
<Grid DataContext="{Binding person2}">
<TextBox Text="Binding Name"/>
</Grid>
Didn't worked. Tried
<Grid>
<TextBox Text="Binding person1.Name"/>
</Grid>
<Grid>
<TextBox Text="Binding person2.Name"/>
</Grid>
Didn't work.
I can bind one person setting DataContext in Window1.cs
But I can't (or don't know how) to set the 2 person as DataContex in Window1.