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

相关推荐
weixin_416660072 分钟前
Mermaid流程图导出到Word:SVG、PNG与清晰度如何选择?
开发语言·c#
公子小六3 小时前
基于.NET的Windows窗体编程之WinForms自定义控件(3)
windows·c#·.net·音视频·winforms
光泽雨19 小时前
动画生命周期
c#·wpf
波力海苔夹心脆6751 天前
C# StringBuilder 详解:字符串拼接为什么总说要用它?
开发语言·笔记·c#·.net·字符串·stringbuilder·入门教程
淡海水1 天前
06-03-源码-时间分片与调度策略
unity·c#·gc
丑梨数据1 天前
法律合同知识库怎么搭:从图片压缩到私有化 RAG 的工程笔记
开发语言·笔记·c#
1-1=01 天前
.NET Core 输出日志
c#·.net·.netcore
曹牧1 天前
C#里引用ActiveX控件
开发语言·c#
宇卿.1 天前
C#委托详解
开发语言·c#
努力,努力再努力1 天前
零依赖 C# Office 库到底怎么用——四个场景讲透 Wisdom.Office
c#