0
我可以綁定到treeveiw的集合,但我不知道熱綁定一個simle對象到wpc控制。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 2010-06-22 18:42:23