<Window x:Class="WPFBind.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpfbind="clr-namespace:WPFBind" xmlns:col="clr-namespace:System.Collections;assembly=mscorlib" Title="MainWindow" Height="780" Width="564"> <Window.Resources> <wpfbind:RawCountToDescriptionConverter x:Key="myConverter"/> </Window.Resources> <StackPanel> <StackPanel> <TextBox Name="txt1" Text="hello" /> <Button Name="btn1" Content="{Binding ElementName=txt1, Path=Text }"></Button> <TextBox Name="btn2" Text="{Binding ElementName=txt1, Path=Text }"></TextBox> </StackPanel> <StackPanel> <Slider Name="slider1" Minimum="10" Maximum="100000" Value="10"></Slider> <TextBox Text="{Binding ElementName=slider1, Path=Value}"></TextBox> </StackPanel> <!--CLR绑定--> <StackPanel> <StackPanel.Resources> <wpfbind:Person x:Key="eric" Name="Eric" /> </StackPanel.Resources> <StackPanel.DataContext> <Binding Source="{StaticResource eric}"></Binding> </StackPanel.DataContext> <Label Content="{Binding Path=Name}" /> </StackPanel> <!--RelativeSource--> <Grid x:Name="g1" Background="Red" Margin="10"> <DockPanel x:Name="d1" Background="Orange" Margin="10"> <Grid x:Name="g2" Background="Yellow" Margin="10"> <DockPanel x:Name="d2" Background="LawnGreen" Margin="10"> <TextBox x:Name="textBox1" FontSize="24" Margin="10" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type TextBox}}, Path=Name}"> </TextBox> </DockPanel> </Grid> </DockPanel> </Grid> <!--DataContext--> <StackPanel> <StackPanel.DataContext> <wpfbind:Person x:Name="person" Name="Jessica" Age="18" ></wpfbind:Person> </StackPanel.DataContext> <Button Content="{Binding Path=Name}"></Button> <Button Content="{Binding Path=Age}"></Button> </StackPanel> <!--ItemsSource--> <StackPanel Background="LightBlue"> <TextBlock Text="Student ID:" FontWeight="Bold"></TextBlock> <TextBox x:Name="txtbox1"></TextBox> <TextBlock Text="Student List:" FontWeight="Bold"></TextBlock> <ListBox x:Name="listBoxStudents" Height="110"></ListBox> </StackPanel> </StackPanel> </Window>