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

相关推荐
yc_122423 分钟前
SqlHelper 实现类,支持多数据库,提供异步操作、自动重试、事务、存储过程、分页、缓存等功能。
数据库·c#
zxfgdjfjfjflfllf38 分钟前
Mapreduce初使用
大数据·wpf·mapreduce
Kookoos1 小时前
Redis + ABP vNext 构建分布式高可用缓存架构
redis·分布式·缓存·架构·c#·.net
Zhen (Evan) Wang3 小时前
ABP-Book Store Application中文讲解 - Part 2: The Book List Page
c#
小乖兽技术4 小时前
在 .NET 8 开发的WinForms 程序中展示程序版本号的几种方式
开发语言·c#·.net
TheWindofFate5 小时前
C# 基础 try-catch代码块
c#·try-catch
TIF星空9 小时前
【使用 C# 获取 USB 设备信息及进行通信】
开发语言·经验分享·笔记·学习·microsoft·c#
csdn_aspnet11 小时前
如何在 C# 中自定义 Datagridview 标题
c#·winform·datagridview
津津有味道11 小时前
MIFARE DESFire Light 卡C#读写更改卡片密钥源码
c#·light·desfire·ev2
炯哈哈14 小时前
【上位机——WPF】Window标签常用属性
开发语言·c#·wpf·上位机