建立一个姓名,年龄输入框,如图:
XAML代码:
<TextBox Name="txtName" Text="{Binding Name}" ToolTip="{Binding Height}" Height="23" HorizontalAlignment="Left" Margin="301,54,0,0" VerticalAlignment="Top" Width="120" />
<TextBox Name="txtAge" Text="{Binding Age}" Height="23" HorizontalAlignment="Left" Margin="301,125,0,0" VerticalAlignment="Top" Width="120" />
<TextBlock Text="姓名" Height="23" HorizontalAlignment="Left" Margin="237,54,0,0" Name="textBlock1" VerticalAlignment="Top" />
<TextBlock Text="年龄" Height="23" HorizontalAlignment="Left" Margin="237,125,0,0" Name="textBlock2" VerticalAlignment="Top" />
建立一个Person Model,里面有Name,Age属性,在窗体加载时设置代码:
打开窗口可以看到:
这时在界面上修改控件上的值就可以直接修改绑定的对象的属性!
但是修改对象的值时,界面上控件的值还不会变化。
下一节:WPF数据双向绑定