日期:2014-05-16 浏览次数:20946 次
class Person
{
public int Age { get; set; }
}
<Window x:Class="WPF1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF1"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Person x:Key="person1"></local:Person>
<Style TargetType="TextBox">
<Setter Property="Text">
<Setter.Value>
<Binding Source="{StaticResource person1}" Path="Age" />
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid HorizontalAlignment="Left" Height="405" VerticalAlignment="Top" Width="533">
<TextBox Name="textbox1" HorizontalAlignment="Left" Height="23" Margin="82,247,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="95,198,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
<Grid HorizontalAlignment="Left" Height="405" VerticalAlignment="Top" Width="533">
<TextBox Name="textbox1" Text="2" HorizontalAlignment="Left" Height="23" Margin="82,247,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="95,198,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
<Style TargetType="TextBox">
<Setter Property="Text" Value="{Binding Source={StaticResource person1}, Path=Age, UpdateSourceTrigger=PropertyChanged}"/>
<Setter Property="FontWeight" Value="Bold"/>
&nb