컬렉션을 treeveiw에 바인딩 할 수 있지만 wpc 제어를위한 하나의 simle 객체를 핫 바인드 할 수는 없습니다.WPF 기본 바인딩 하나의 객체
<UserControl x:Class="ReporterWpf.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<StackPanel>
<TextBox Name="{Binding Path=Name}"></TextBox>
<TextBox Name="{Binding Path=Age}"></TextBox>
</StackPanel>
</Grid>
</UserControl>
public Person
{
public string Name {get;set;}
public int Age {get;set;}
}
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public UserControl1(Person person):this()
{
Person person=new Person();
person.Age=19;
person.Name = "Patrick"
}
}
이 두 속성을 바인딩하는 마법의 줄은 무엇입니까?
+1 .. 이것은 가장 간단한 방법이지만 DataContext를 설정하기위한 몇 가지 옵션이 있습니다. 폴 스토벨 (Paul Stovell)은 여기에서 옵션을 탐구했다 : http://www.paulstovell.com/mvvm-instantiation-approaches – kiwipom