程序集整体框架如下

WPF 绑定到类成员

 

 MainWindow前台代码中Text="{Binding Stu.Name}", Text="{Binding Stu.Gender}" ,Text="{Binding Stu.Age}"都是绑定到类成员

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid x:Name="GuanJiaoGrid">
        <Grid.DataContext>
            <local:Students></local:Students>
        </Grid.DataContext>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <Label Grid.Row="0" HorizontalAlignment="Center" Grid.Column="1" VerticalAlignment="Center" FontSize="22" >名字</Label>
        <Label Grid.Row="0" HorizontalAlignment="Center" Grid.Column="2" VerticalAlignment="Center" FontSize="22" >性别</Label>
        <Label Grid.Row="0" HorizontalAlignment="Center" Grid.Column="3" VerticalAlignment="Center" FontSize="22" >年龄</Label>

        <TextBox  Text="{Binding Stu.Name}"      Grid.Column="1" Grid.Row="1" TextAlignment="Center" FontSize="22" ></TextBox>
        <TextBox  Text="{Binding Stu.Gender}"    Grid.Column="2" Grid.Row="1" TextAlignment="Center" FontSize="22" ></TextBox>
        <TextBox  Text="{Binding Stu.Age}"       Grid.Column="3" Grid.Row="1" TextAlignment="Center" FontSize="22" ></TextBox>
    </Grid>
</Window>
MainWindow.xaml

相关文章:

  • 2021-10-12
  • 2021-05-22
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案