1.概要
1.1 定义内容的外观
2.2 要点分析
2.代码
<Window x:Class="WpfApp2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Window.Resources>
<DataTemplate x:Key="template1">
<TextBlock Text="{Binding}" FontSize="15" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
<DataTemplate x:Key="template2">
<TextBlock Text="这是模板定义的内容" FontSize="15" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ContentControl ContentTemplate="{StaticResource template1}"
Content="这是控件的内容."/>
<ContentControl ContentTemplate="{StaticResource template2}" />
</StackPanel>
</Window>
3.运行结果