<Window x:Class="WpfApp_Delete.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" xmlns:Custom="clr-namespace:WpfApp_Delete" > <Window.Resources> <Custom:DemoList x:Key="MyList"> <Custom:Demo Address="黄石" Sex="男" /> <Custom:Demo Address="铁山" Sex="女"/> </Custom:DemoList> <Custom:Demo x:Key="MyDemo" Address="黄石" Sex="男" /> </Window.Resources> <Grid DataContext="{StaticResource MyList}"> <Grid.Resources> <!--x:Null的事例--> <Style TargetType="Button"> <Setter Property="Width" Value="200"/> </Style> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> </Grid.Resources> <TextBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBox1" Text="{Binding ElementName=lvRoot, Path=SelectedItem.Sex}" VerticalAlignment="Top" Width="120" /> <ListView Name="lvRoot" Height="100" HorizontalAlignment="Left" Margin="10,43,0,0" VerticalAlignment="Top" Width="481" ItemsSource="{Binding}" > <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding Address}" Header="住址" Width="100"/> <GridViewColumn DisplayMemberBinding="{Binding Sex}" Header="性别" Width="100"/> </GridView> </ListView.View> </ListView> <!--x:Null的事例--> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="35,157,0,0" Name="button1" VerticalAlignment="Top" /> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="265,157,0,0" Name="button2" Style="{x:Null}" VerticalAlignment="Top" /> </Grid> </Window>