1. 程式人生 > >WPF Demo17 數據綁定

WPF Demo17 數據綁定

tac width http back gin present namespace 實例 pre

實例一:以資源的形式實現

技術分享

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>

技術分享

WPF Demo17 數據綁定