<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. File类与常用IO流第十章——序列化流

    第十章.序列化流 序列化流和反序列化流概述 序列化:用一个字节序列表示一个对象,该字节序列包含该对象的数据.对象的类型和对象中存储的属性等等信息.字节序列写出到文件后,相当于文件中持久保存了一个对象的 ...

  2. 使用jquery的on方法注册事件遇到的坑

    1,使用on注册事件 $(selector).on(event,childSelector,data,function) 2,$(selector)中的selector可以是document,那么意味 ...

  3. Appium - adb monkey事件(二)

    操作事件简介 Monkey所执行的随机事件流中包含11大事件,分别是触摸事件.手势事件.二指缩放事件.轨迹事件.屏幕旋转事件.基本导航事件.主要导航事件.系统按键事件.启动Activity事件.键盘事 ...

  4. 【爬虫系列】0. 无内鬼,破解前端JS参数签名

    PS:这是一个系列,坐等我慢慢填坑. PS:不太会直接能跑的代码,抛砖引玉. PS:那些我也不太熟练的就不搞了,包括(破滑块.验证码..) PS: 反编译搞Apk会有很长的几个文章,稍后慢慢更. 最近 ...

  5. 什么是 BPMN ?为什么我们要用 BPMN 和工作流 ?

    BPMN 和 Activiti 介绍 工作流介绍 在任何行业和企业中,都有各种各样的流程,例如: 请假流程 报销流程 入职流程 离职流程 出差流程 等等-- 就算你自己没有设计过工作流,那么你每天肯定 ...

  6. 【洛谷1339 [USACO09OCT]】热浪Heat Wave 图论+最短路

    AC代码 #include<bits/stdc++.h> using namespace std; const int MAXN=62000+10,INF=999999; struct E ...

  7. Java字节码增强技术

    简单介绍下几种java字节码增强技术. ASM ASM是一个Java字节码操控框架,它能被用来动态生成类或者增强既有类的功能.ASM可以直接产生class文件,也可以在类被加载入Java虚拟机之前动态 ...

  8. Deepin 20.2.2 /UOS 20.2 添加ppa源

    由于 工作需要,需要通过PPA安装一些优质的软件包,但是 Deepin 默认不支持PPA源 解决方法 由于Deepin/Uos系统默认是没有安装PPA的那么我们得先安装PPA来支持"add- ...

  9. 版本号是通过import合并而来的,不是继承来的

  10. 17Java进阶——反射、进程、Java11新特性

    1.Java反射机制 Java反射(Reflection)概念:在运行时动态获取类的信息以及动态调用对象方法的功能. 1.1反射的应用--通过全类名获取类对象及其方法 package two.refl ...