<Window x:Class="WpfApplication1.Window38"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window38" Height="227" Width="269">
<Window.Resources>
<!--数据对象-->
<local:Student38 x:Key="stu" Id="1" Skill="WPF" Name="Timothy" HasJob="True"></local:Student38>
<!--DataTemplate-->
<DataTemplate x:Key="dtStu">
<Border BorderBrush="Orange" BorderThickness="2" CornerRadius="5">
<StackPanel>
<TextBlock Text="{Binding Id}" Margin="5"></TextBlock>
<TextBlock x:Name="txtBlockName" Text="{Binding Name}" Margin="5"></TextBlock>
<TextBlock Text="{Binding Skill}" Margin="5"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<!--主窗体布局-->
<StackPanel>
<ContentPresenter x:Name="cp" Content="{StaticResource stu}" ContentTemplate="{StaticResource dtStu}" Margin="5">
</ContentPresenter>
<Button Content="Find" Margin="5,0" Click="Button_Click">
</Button>
</StackPanel>
</Window>
-----------------------------------------------------------------------------------------------------
标签:dataTemplate,-------------------------------------------------------------------
From: https://blog.51cto.com/u_4018548/6420068