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

相关推荐
xiaoshuaishuai82 小时前
C# GPU算力与管理
开发语言·windows·c#
hez20104 小时前
C# 15 类型系统改进:Union Types
c#·.net·.net core
FL16238631295 小时前
基于C#winform部署软前景分割DAViD算法的onnx模型实现前景分割
开发语言·算法·c#
C#程序员一枚6 小时前
高可用(High Availability, HA)
数据库·c#
weixin_520649876 小时前
C#进阶-特性全知识点总结
开发语言·c#
fengyehongWorld7 小时前
C# 创建vba用的类库
c#
澄澈青空~8 小时前
有一个叫R2C,也有一个叫G2C
java·数据库·人工智能·c#
PGFA10 小时前
深度剖析 C# LINQ 底层执行机制:别让你的应用内存莫名其妙“爆”掉!
c#·solr·linq
2601_9498146911 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互
CSharp精选营12 小时前
C#事务处理最佳实践:别再让“主表存了、明细丢了”的破事发生
c#·try-catch·事务处理·transactionscope