<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. 「CF521D」 Shop

    「CF521D」 Shop 传送门 题目说是有三种操作,首先可以知道赋值操作是可以转化为加法操作的,即 \((1,b) \rightarrow (2,b-a_i)\) 然后加法对于一个数你肯定优先选择 ...

  2. C语言:伪代码

    伪代码(Pseudocode)是一种算法描述语言.使用伪代码的目的是为了使被描述的算法可以容易地以任何一种编程语言(C, Java, Pascal)实现.因此,伪代码必须结构清晰,代码简单,可读性好, ...

  3. HTML5-CSS(四)

    一.CSS3 渐变效果 (1)CSS3 提供了 linear-gradient 属性实现背景颜色的渐变功能.首先,我们先看一下它的样式表,如下: //两个必须参数background-image: l ...

  4. python + pytest 基本使用方法(Fixture)

    #firtures通常用来对测试方法.测试函数.测试类和整个测试文件进行初始化或还原测试环境# setup_module/teardown_module:在当前文件中,在所有测试用例执行之前与之后执行 ...

  5. 【Mysql】InnoDB 中的 B+ 树索引

    接上一篇内容,InnoDB 的作者想到一种更灵活的方式来管理所有目录项,是什么? 一.目录项记录页 其实这些用户目录项与用户记录很像,只是目录项中的两个列记录的是主键和页号而已,那么就可以复用之前存储 ...

  6. 每天五分钟Go - 指针

    什么是指针 一个指向内存地址的变量,称为指针变量,指针是一个特殊的变量,他的值存储的是另一个值的内存地址 指针变量的声明 var var_name *type var_name 是指针变量的名称,ty ...

  7. 1.4matlab矩阵的表示

    1.4matlab矩阵的表示 矩阵的建立 利用直接输入法建立矩阵:将矩阵的元素用中括号括起来,按矩阵的顺序输入各元素,同一行的各元素之间用逗号或空格分隔,不同行的元素之间用分号分隔. 利用已建立好的矩 ...

  8. 🔥 LeetCode 热题 HOT 100(81-90)

    337. 打家劫舍 III 思路:后序遍历 + 动态规划 推荐题解:树形 dp 入门问题(理解「无后效性」和「后序遍历」) /** * Definition for a binary tree nod ...

  9. Docker与k8s的恩怨情仇(七)—— “服务发现”大法让你的内外交互原地起飞

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 第一章:Docker与k8s的恩怨情仇(一)-成为PaaS前浪的Cloud Foundry 第二章:Dock ...

  10. Thunder DLL Hijacking

    简记 原理基础啥的俺也不写了 1.寻找DLL 生成恶意dll文件 拿calc测试 2.放入 3.打开