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

相关推荐
yngsqq14 小时前
批量裁剪——CAD一键根据裁剪框裁剪
c#
天才奇男子14 小时前
LVS原理及部署
linux·运维·云原生·wpf·lvs·linux chrony
予枫的编程笔记16 小时前
【Redis实战进阶篇1】Redis 分布式锁:从手写实现到 Redisson 最佳实践
redis·分布式·wpf
东边的小山17 小时前
python 图形界面多个WORD按名字排序合并成一个WORD
python·c#·word
大王小生1 天前
说说CSV文件和C#解析csv文件的几种方式
人工智能·c#·csv·csvhelper·csvreader
LongtengGensSupreme1 天前
C# 中监听 IPv6 回环地址----HttpListener
c#·ipv6·httplistener
zzcufo1 天前
多邻国学习笔记第五阶段第10-11部分
笔记·学习·c#
easyboot1 天前
C#使用pythonnet简单示例
开发语言·python·c#
刘欣的博客2 天前
c# winform 控件dock 停造位置、摆放顺序问题
c#·winform·dock停靠问题
Java程序员威哥2 天前
Arthas+IDEA实战:Java线上问题排查完整流程(Spring Boot项目落地)
java·开发语言·spring boot·python·c#·intellij-idea