欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

实例一:以资源的形式实现

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>

 

posted on 2017-05-18 13:54  sunwugang  阅读(233)  评论(0编辑  收藏  举报