WPF 中的DataTemplate 的嵌套

<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 的嵌套的更多相关文章
- WPF中的DataTemplate
<Window x:Class="DateTemplate应用.MainWindow" xmlns="http://schemas.microsoft.com/wi ...
- wpf 中的DataTemplate 绑定控件
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...
- WPF中UserControl和DataTemplate
最新更新: http://denghejun.github.io 前言 前言总是留给我说一些无关主题的言论,WPF作为全新Microsoft桌面或web应用程序显示技术框架, 从08年开始,一直到现在 ...
- WPF中的数据模板(DataTemplate)(转)
原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate) ...
- WPF中的数据模板(DataTemplate)
原文:WPF中的数据模板(DataTemplate) WPF中的数据模板(DataTemplate) ...
- WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探
原文:WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探 最近因为项目需要,开始学习如何使用WPF开发桌面程序.使用WPF一段时间之后,感 ...
- wpf中在style的template寻找ControlTemplate和DataTemplate的控件
一.WPF中的两棵树 WPF中每个控件的Template都是由ControlTemplate构成,ControlTemplate包含了构成该控件的各种子控件,这些子控件就构成了VisualTree:而 ...
- WPF入门教程系列十八——WPF中的数据绑定(四)
六.排序 如果想以特定的方式对数据进行排序,可以绑定到 CollectionViewSource,而不是直接绑定到 ObjectDataProvider.CollectionViewSource 则会 ...
- WPF中的数据绑定!!!
引用自:https://msdn.microsoft.com/zh-cn/magazine/cc163299.aspx 数据点: WPF 中的数据绑定 数据点 WPF 中的数据绑定 John Pap ...
随机推荐
- C语言:预处理命令总结
预处理指令是以#号开头的代码行,# 号必须是该行除了任何空白字符外的第一个字符.# 后是指令关键字,在关键字和 # 号之间允许存在任意个数的空白字符,整行语句构成了一条预处理指令,该指令将在编译器进行 ...
- python adb 关闭拼多多
def gbpdd(sjh): aaka="adb -s {0} shell am force-stop com.xunmeng.pinduoduo".format(sjh) aa ...
- 前端开发入门到进阶第二集【emmet插件的使用技巧】
Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具.基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为"片段".虽然片段能很好 ...
- 【Mysql】InnoDB 中的聚簇索引、二级索引、联合索引
接上一篇内容. 一.聚簇索引 其实之前内容中介绍的 B+ 树就是聚簇索引. 这种索引不需要我们显示地使用 INDEX 语句去创建,InnoDB 引擎会自动创建.另外,在 InnoDB 引擎中,聚簇索引 ...
- sql语句优化(持续更新)
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引.2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引 ...
- 01MATLAB导论
MATLAB语言的主要功能 数值计算 符号计算 图形绘制 程序流程控制 工具箱 课程的学习目标 要求理解MATLAB功能实现的数学背景与算法原理 掌握利用MATLAB进行问题求解的基本规律 能够利用M ...
- 解决跨网段intouch嵌入视频问题
在自控项目中,一般会将视频网络和自控网络分开,分属于两个不同的逻辑网段,以避免局域网ip不够用的问题.这就造成了一个问题,如何实现在自控网络上位机访问摄像头并嵌入使用?这里其实很简单,因为这两个网络本 ...
- GitHub秘钥(SSH Key)
一.公钥的作用 公钥一般给服务器,别人权限中加入我给的公钥,当我们从远地仓库中下载项目(git clone xxx)的时 那个服务器通过他的绑定的公钥来匹配我的私钥,如果匹配,则就可以正常下载,如果不 ...
- js 跨域请求失败
注:错误返回:Failed to load http://xxxxxxxxxxx: No 'Access-Control-Allow-Origin' header is present on the ...
- 卷积的等变性(equivariant) / 不变性(invariant)
不变性:输入x发生变换,但是F之后的输出不变 \(F(x)=F [\)transform\((x)]\) 池化:近似不变性,当图像发生微小变化,最大池化的输出不变,还是一个池化范围内的max 等变性: ...