本帖最后由 陈振宇 于 2013-3-10 21:53 编辑
<Window x:Class="数据绑定.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Loaded="Grid_Loaded">
<TextBox Height="23" Text="{Binding Name}" ToolTip="mima" HorizontalAlignment="Left" Margin="71,28,0,0" Name="txtName" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" Text="{Binding Age}" HorizontalAlignment="Left" Margin="71,68,0,0" Name="txtAge" VerticalAlignment="Top" Width="120" />
<Button Content="Name显示" Height="23" HorizontalAlignment="Left" Margin="225,28,0,0" Name="btnName" VerticalAlignment="Top" Width="75" Click="btnName_Click" />
<Button Content="Age显示" Height="23" HorizontalAlignment="Right" Margin="0,68,203,0" Name="betAge" VerticalAlignment="Top" Width="75" Click="betAge_Click" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,29,0,0" Name="textBlock1" Text="姓名" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,68,0,0" Name="textBlock2" Text="年龄" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="12,112,0,0" Name="textBlock3" Text="身高" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,151,0,0" Name="textBlock5" Text="性别" VerticalAlignment="Top" />
<TextBox Height="23" Text="{Binding height}" HorizontalAlignment="Left" Margin="71,109,0,0" Name="txtHeight" VerticalAlignment="Top" Width="120" />
<CheckBox IsChecked="{Binding Gender}" Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="71,151,0,0" Name="ckBox" VerticalAlignment="Top" />
<Button Content="Height显示" Height="23" HorizontalAlignment="Left" Margin="225,112,0,0" Name="btnheight" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace 数据绑定
{
class person:INotifyPropertyChanged
{
private int age;
public int Age
{
get
{
return age;
}
set
{
this.age=value;
if (PropertyChanged!=null)
{
PropertyChanged(this ,new PropertyChangedEventArgs("Age"));
}
}
}
public string Name
{
get;
set;
}
public bool Gender
{
get;
set;
}
public int Height
{
get;
set;
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
|