class Student {
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}Xaml中进行绑定
<Window x:Class="Wpf基础学习.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Wpf基础学习"
Title="MainWindow" Height="350" Width="525">
<StackPanel Background="LightBlue">
<StackPanel.DataContext>
<local:Student Id="6" Age="29" Name="Time"/>
</StackPanel.DataContext>
<Grid>
<StackPanel>
<TextBox Text="{Binding Path=Id}" Margin="5" Background="Red" />
<TextBox Text="{Binding Path=Name}" Margin="5" Background="Red" />
<TextBox Text="{Binding Path=Age}" Margin="5" Background="Red" />
</StackPanel>
</Grid>
</StackPanel>
通过
xmlns:local="clr-namespace:Wpf基础学习"可以访问类Student,从类中获得数据
这是wpf当中典型数据绑定模式。
本文介绍了一个WPF应用程序的数据绑定实例,展示了如何在XAML中绑定本地类Student的属性到UI元素上。
405

被折叠的 条评论
为什么被折叠?



