<Window x:Class="WPF.MainWindow"

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:WPF"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

<Window.Resources>

<DataTemplate x:Key="kk">

<Grid>

<Grid.RowDefinitions>

<RowDefinition></RowDefinition>

<RowDefinition></RowDefinition>

</Grid.RowDefinitions>

<Button>222222222</Button>

<Ellipse Grid.Row="1" Height="50" Width="50" Fill="Red">

</Ellipse>

</Grid>

</DataTemplate>

<DataTemplate x:Key="studentItemTemplate">

<Grid>

<Rectangle Fill="Red" Width="200" Height="200"></Rectangle>

</Grid>

</DataTemplate>

<DataTemplate x:Key="studentJudgeTemplate">

<Grid>

<Grid.RowDefinitions>

<RowDefinition></RowDefinition>

<RowDefinition></RowDefinition>

</Grid.RowDefinitions>

<Label >this is template 222</Label>

<Label Grid.Row="1" ContentTemplate="{StaticResource studentItemTemplate}">

</Label>

</Grid>

</DataTemplate>

</Window.Resources>

<Grid>

<Label ContentTemplate="{StaticResource studentJudgeTemplate}">

</Label>

</Grid>

</Window>

content presentor 的使用

------------------------------------------------------------

<UserControl x:Class="WPF.Login"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:local="clr-namespace:WPF"

mc:Ignorable="d"

d:DesignHeight="450" d:DesignWidth="800" x:Name="uc">

<UserControl.Resources>

<Style x:Key="kk" TargetType="Label">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="Label">

<Grid>

<Ellipse Margin="34,45,44,117" Fill="{TemplateBinding Background}"/>

</Grid>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</UserControl.Resources>

<Grid>

<Grid.RowDefinitions>

<RowDefinition></RowDefinition>

<RowDefinition></RowDefinition>

</Grid.RowDefinitions>

<Button Grid.Row="0">111111111111</Button>

<ContentPresenter Grid.Row="1" x:Name="lab" Content="{Binding MM}">

<!--<Ellipse Width="100" Height="100" Fill="Red">

</Ellipse>-->

</ContentPresenter>

</Grid>

</UserControl>

C# code

-------------------------

public partial class Login : UserControl

{

public Login()

{

InitializeComponent();

this.Loaded += Login_Loaded;

this.DataContext = this;

}

private void Login_Loaded(object sender, RoutedEventArgs e)

{

}

public static readonly DependencyProperty MMProperty = DependencyProperty.Register("MM", typeof(object), typeof(Login));

public object MM

{

get { return (object)GetValue(MMProperty); }

set { SetValue(MMProperty, value); }

}

private static bool setV(Object obj)

{

// lab.Content = obj;

return true;

}

}

WPF 中的DataTemplate 的嵌套的更多相关文章

  1. WPF中的DataTemplate

    <Window x:Class="DateTemplate应用.MainWindow" xmlns="http://schemas.microsoft.com/wi ...

  2. wpf 中的DataTemplate 绑定控件

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

  3. WPF中UserControl和DataTemplate

    最新更新: http://denghejun.github.io 前言 前言总是留给我说一些无关主题的言论,WPF作为全新Microsoft桌面或web应用程序显示技术框架, 从08年开始,一直到现在 ...

  4. WPF中的数据模板(DataTemplate)(转)

    原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate)        ...

  5. WPF中的数据模板(DataTemplate)

    原文:WPF中的数据模板(DataTemplate) WPF中的数据模板(DataTemplate)                                                   ...

  6. WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探

    原文:WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探         最近因为项目需要,开始学习如何使用WPF开发桌面程序.使用WPF一段时间之后,感 ...

  7. wpf中在style的template寻找ControlTemplate和DataTemplate的控件

    一.WPF中的两棵树 WPF中每个控件的Template都是由ControlTemplate构成,ControlTemplate包含了构成该控件的各种子控件,这些子控件就构成了VisualTree:而 ...

  8. WPF入门教程系列十八——WPF中的数据绑定(四)

    六.排序 如果想以特定的方式对数据进行排序,可以绑定到 CollectionViewSource,而不是直接绑定到 ObjectDataProvider.CollectionViewSource 则会 ...

  9. WPF中的数据绑定!!!

    引用自:https://msdn.microsoft.com/zh-cn/magazine/cc163299.aspx  数据点: WPF 中的数据绑定 数据点 WPF 中的数据绑定 John Pap ...

随机推荐

  1. ms17-010 永恒之蓝漏洞复现(CVE-2017-0143)

    0x01 首先对目标机的开放端口进行探测,我们可以使用探测神器nmap 发现开放的445端口,然后进行下一步的ms17-010的漏洞验证 0x02 打开MSF美少妇神器,用search命令搜索ms17 ...

  2. STP、生成树的算法

    STP.生成树的算法       一.STP        1)STP概述        2)交换网络环路的产生        3)STP简介        4)STP的工作原理        5)S ...

  3. MySQL主从复制的简单搭建

    @ 目录 1.MySQL一主一从的简单搭建 1.1.主从复制简介 1.2.MySQL主从复制简介 1.3.主从复制的架构 1.4.前期准备 1.5.主要配置实现 1.5.1.测试环境 1.5.2.配置 ...

  4. Spark—RDD介绍

    Spark-RDD 1.概念介绍 RDD(Resilient Distributed Dataset):弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区.里面的元素可并行计算 ...

  5. 两台Linux系统之间传输文件的几种方法

    两台Linux系统之间传输文件的几种方法:参考https://www.cnblogs.com/bignode/articles/9241333.html

  6. 使用deepin连接罗技k380

    1,刚开始总是连不上,连上了就断开了,以为是deepin系统的问题. 2,首先在华为论坛上找到这样的一片解决方案:https://cn.ui.vmall.com/thread-21831568-1-1 ...

  7. mybatis-7-缓存

    1. 一级缓存: SqlSession 级别, 默认开启, 并且不能关闭 操作数据库是需要创建 SqlSession 对象, 在对象中有一个 HashMap 用于存储缓存数据, 不同的 SqlSess ...

  8. Python基础之用PyQt5创建menu

    前一篇文章中,我们已经安装了PyQt5,并且已经测试过可用.那么接下来第一步开始学习如何创建菜单. 第一步:在想要运行py的地方右击External Tools-->designer,打开des ...

  9. rsync(873)未授权访问

    cd vulhub-master/rsync/common docker -composeup -d 检测 1.列出目标服务器的同步目录 rsync 192.168.244.129:: 2.查看模块文 ...

  10. Python小白的数学建模课-12.非线性规划

    非线性规划是指目标函数或约束条件中包含非线性函数的规划问题,实际就是非线性最优化问题. 从线性规划到非线性规划,不仅是数学方法的差异,更是解决问题的思想方法的转变. 非线性规划问题没有统一的通用方法, ...