<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. ES6新增语法(三)——面向对象

    ES6中json的2个变化 简写:名字和值相同时,json可以可以简写 let a=12,b=5; let json = { a, b } console.log(json) // { a:12 , ...

  2. Java多线程系列-基本概念

    Java的线程基本用法 创建线程 创建线程的方法: 实现Runnable接口 首先我们查看Runnable接口的定义: package java.lang; @FunctionalInterface ...

  3. 【LeetCode】523. 连续的子数组和

    523. 连续的子数组和 知识点:数组:前缀和: 题目描述 给你一个整数数组 nums 和一个整数 k ,编写一个函数来判断该数组是否含有同时满足下述条件的连续子数组: 子数组大小 至少为 2 ,且 ...

  4. Unittest方法 -- 测试报告&加载测试类(discover)

    import unittestimport HTMLTestRunnerimport osclass F11(unittest.TestCase): def test_001(self): self. ...

  5. CF404D-DP【成就达成】

    CF404D-DP 正经的东西 题意 给定一个字符串,只包含'0','1','2','*','?'五种字符,其中'?'可被替换为其他任何一种,求使序列符合扫雷地图定义的方案数. 一个数字字符大小表示与 ...

  6. selenium定位,操作元素

    1.定位方式 1.id driver.find_element_by_id('username').send_keys('byhy') 2.name driver.find_element_by_na ...

  7. Python基础之实现界面和代码分离

    第一步:用QT Designer画一个TreeWidget,存为treeview4.ui,这个处理前面TreeWidget那一节讲过,这里不细讲 treeview4.py # -*- coding: ...

  8. Docker run 命令参数及使用

    Docker run 命令参数及使用 Docker run :创建一个新的容器并运行一个命令 语法 docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTI ...

  9. (JAVA3)MarkDown语法

    (三)MarkDown语法 分级标题(用 #数量 表示 级标题) #+空格+一级标题+回车 = 一级标题 ##+空格+二级标题+回车 = 二级标题 ###+空格+三级标题+回车 = 三级标题 加粗 选 ...

  10. 跳转页面携带数据方法 js

    跳转页面 代码 function returnParent() { var arrReturn = new Array(); var tSel = LAAccountsGrid.getSelNo(); ...