c# wpf Template ContentTemplate

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.运行结果

相关推荐
The Future is mine1 小时前
C# new Bitmap(32043, 32043, PixelFormat.Format32bppArgb)报错:参数无效,如何将图像分块化处理?
开发语言·c#
Iotfsd8 小时前
.NET写的开源工业物联网网关(IoTGateway)
物联网·c#·.net·dotnet·边缘网关·雾计算·工业物联网智能网关
先生沉默先8 小时前
c#接口_抽象类_多态学习
开发语言·学习·c#
江沉晚呤时9 小时前
深入了解C# List集合及两种常见排序算法:插入排序与堆排序
windows·sql·算法·oracle·c#·排序算法·mybatis
iReachers9 小时前
使用命令行加密混淆C#程序
开发语言·c#
[太阳]889 小时前
Kafka命令行的使用/Spark-Streaming核心编程(二)
c#·linq
电商api接口开发1 天前
ASP.NET MVC 入门指南
c#·asp.net·mvc
我不是程序猿儿1 天前
[C#]反射的实战应用,实际数据模拟
开发语言·c#
爱编程的鱼1 天前
C# 结构(Struct)
开发语言·人工智能·算法·c#
是阿根1 天前
unity使用iTextSharp生成PDF文件
unity·c#·游戏引擎