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 ...
随机推荐
- Nacos源码分析-事件发布机制
温馨提示: 本文内容基于个人学习Nacos 2.0.1版本代码总结而来,因个人理解差异,不保证完全正确.如有理解错误之处欢迎各位拍砖指正,相互学习:转载请注明出处. Nacos的服务注册.服务变更等功 ...
- [刘阳Java]_第一个Java程序_第7讲
1. 其实第一个Java程序是很简单,但是当自己编写第一个Java程序时候需要注意如下几个内容: 理解Java程序的运行环境 校验你的Java环境变量是否能够运行你所写的第一个Java程序 理解Jav ...
- 【技巧】使用PPT更换背景色
主要记述使用PPT来更换图片某一部分的背景色 把想要更改的图片粘贴到PPT里. 依次选择[格式][颜色][设置透明色],然后点击需要更改背景的地方 将自己的目标颜色复制一下,填充上去,选择[置于底层]
- P5147-数学-随机数生成器
P5147-数学-随机数生成器 (洛谷第一篇题解说这是高一数学题,新高二感觉到被吊打) 我们设work(x)的期望值为\(f_x\) 注意\(f_1\)是边界.不过对下列式子没有影响.原因参照必修的数 ...
- C++第四十六篇 -- C++将int转换成宽字符串
int rate = 60; int score = 80 TCHAR Temp[64] = TEXT(""); _stprintf_s(Temp, TEXT("pass ...
- No_1 手写Proxy
手写动态代理主要原理: userDAO=(UserDAO)Proxy.newProxyinstance(classloader,interfaces[],new MyInvocationHandler ...
- vue源码阅读笔记
1.yarn test [文件名] -t [name-of-spec(describe or test )] 直接运行yarn test,会测试所有测试文件:yarn test 后面只跟文件名的话会 ...
- Winform中生成自动控件
场景: 前几天项目需要模拟数据,但是实际设备还没有接上,就自己用Winform搭建了一个数据模拟器,生成数据给平台.这里又一个需求,就是从数据库中找出设备,然后自动生成控件,勾选就表示开启该设备,能上 ...
- 适合普通大学生的 Java 后端开发学习路线
大家好,我是帅地. 接下来的一段时间,帅地会总结各种技术栈的学习路线,例如 Java 开发,C++ 开发,python 开发,前端开发等等,假如你没有明确的目标,或许可以按照我说的学习路线来学习一波, ...
- Python RPC 不会?不妨看看这篇文章
1. 前言 大家好,我是安果! RPC,全程为 Remote Procedure Call,是一种进程间的通信方式,它采用「 服务端 / 客户机 」模式,是一种请求响应模型 其中,服务端负责提供服务程 ...