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

相关推荐
Young_Gnay20 小时前
.NET 之 WebApi学习笔记 (持续更新)
后端·c#
李高钢21 小时前
WPF MVVM Light 入门:从零到Hello World
c#·wpf
曹牧1 天前
C#:函数参数指定默认值
开发语言·c#
李高钢1 天前
WPF MVVM Light(三):RelayCommand 命令与 Messenger 消息
前端·c#·wpf
曹牧1 天前
C#:字符串做20位截断
开发语言·c#
离陌在学C#2 天前
C# 事件(Event)详解:从概念到实战
开发语言·c#
rockey6272 天前
C#脚本引擎之AScript与Flee对比
c#·.net·script·eval·动态脚本
zjnlswd2 天前
C#学习笔记4
笔记·学习·c#
曹牧2 天前
C#:List<string>特定格式输出
windows·c#
Z5998178412 天前
c#软件开发学习笔记--Modbus-TCP/UDP网口通讯
笔记·学习·c#