WPF中的数据绑定非常的灵活,使用起来也是十分的简单,这里我不扯什么理论知识了发个链接 想仔细研究的同学 可以自己去慢慢看
MSDN http://msdn.microsoft.com/zh-cn/library/ms752347(v=vs.100).aspx
本文主要是针对那些个想迅速了解数据绑定 直接上手的同学所写,废话不多说 上代码
<Window x:Class="DataBindingDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="700" Width="525">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="10" >
<TextBlock Text="Binding DependencyObject Property:" FontWeight="Bold"/>
<TextBox x:Name="DP_Property" Text="test text" />
<TextBlock Text="{Binding ElementName=DP_Property,Path=Text}" ToolTip="{Binding RelativeSource={RelativeSource self},Path=Text}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10" >
<TextBlock Text="Binding CLR Object Property:" FontWeight="Bold"/>
<TextBlock x:Name="TBSimpaleCLR" Text="{Binding ShowText}"/>
<Button Width="70" Height="30" Content="auto update text" Click="AutoUpdateCLRProperty_Click"/>
</StackPanel>
<StackPanel Margin="10" >
<TextBlock Text="Binding CLR Object List:" FontWeight="Bold"/>
<ItemsControl x:Name="IC_CLRList">
<ItemsControl.ItemTemplate>