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

相关推荐
CSDN_RTKLIB4 小时前
LTSCALE
c#
Behaviour4 小时前
Unity 手游网络同步技术
网络·unity·c#·游戏引擎
Vae_Mars5 小时前
WPF中的ControlTemplate(控件模板)
wpf
LccKyI5 小时前
# C# 基础编程 面试题汇总(一)
开发语言·c#
祀爱5 小时前
C# MQTT 连接服务
后端·c#·.net
SamChan905 小时前
Python+ReportLab自动生成PDF翻译质量审计报告:从数据到可视化的完整方案
开发语言·python·ai·pdf·wpf
circuitsosk6 小时前
多智能体协同在能源数据分析中的实践:分配-执行-校验闭环架构设计
python·数据分析·wpf·能源·并行计算·多智能体系统·agent协作
LccKyI6 小时前
C#基础编程 面试题汇总(二)
java·面试·c#
Behaviour17 小时前
Unity UI循环列表UIScrollViewContent实现
ui·unity·c#·游戏引擎
c#上位机17 小时前
C#上位机项目实战——C#的dll项目编译时拷贝到指定目录下
开发语言·c#