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

相关推荐
c#上位机5 小时前
halcon多个区域合并为1个区域—union1
c#·上位机·halcon·机器视觉
c#上位机5 小时前
halcon图像增强——图像取反
图像处理·算法·c#·halcon
zwm2698888155 小时前
悦龙台 监控掉线问题
c#
c#上位机5 小时前
halcon图像去噪—导向滤波
图像处理·人工智能·计算机视觉·c#·halcon
切糕师学AI6 小时前
Z.EntityFramework.Extensions.Core 如何批量删除数据?
c#
CHANG_THE_WORLD6 小时前
Python 中的循环结构详解
开发语言·python·c#
c#上位机7 小时前
halcon获取多个独立连通域—connection
图像处理·c#·halcon
关关长语12 小时前
HandyControl 3.5.x 版本 ListViewItem不显示问题
windows·wpf
Macbethad12 小时前
工业设备维护程序技术方案
wpf
烛阴12 小时前
代码的“病历本”:深入解读C#常见异常
前端·c#