实例一:以资源的形式实现
namespace 数据绑定1 { public class Student { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } } }
<Window x:Class="数据绑定1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:数据绑定1" 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> </Window>
时间: 2024-11-13 09:59:50