WPF中的DataTemplate
<Window x:Class="DateTemplate应用.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DateTemplate应用"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--DataTemplate-->
<DataTemplate DataType="{x:Type local:Unit}">
<Grid>
<StackPanel Orientation="Horizontal">
<Grid>
<Rectangle Stroke="Yellow" Fill="Orange" Width="{Binding Price}"/>
<TextBox Text="{Binding Year}"/>
</Grid>
<TextBlock Text="{Binding Price}" Margin="5,0"/>
</StackPanel>
</Grid>
</DataTemplate>
<!--数据源-->
<collections:ArrayList x:Key="ds">
<local:Unit Year="2001" Price="100"/>
<local:Unit Year="2002" Price="120"/>
<local:Unit Year="2003" Price="140"/>
<local:Unit Year="2004" Price="160"/>
<local:Unit Year="2006" Price="180"/>
<local:Unit Year="2008" Price="200"/>
</collections:ArrayList>
</Window.Resources>
<StackPanel>
<ListBox ItemsSource="{StaticResource ds}"/>
<ComboBox ItemsSource="{StaticResource ds}"/>
</StackPanel>
</Window>
以XML数据格式来显示
<Window x:Class="XMLDataTemplate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xmlDataTemplate="clr-namespace:XMLDataTemplate"
Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen">
<Window.Resources>
<!--DataTemplate-->
<DataTemplate x:Key="MyXmlDataTemplate">
<Grid>
<StackPanel Orientation="Horizontal">
<Grid>
<Rectangle Stroke="Yellow" Fill="Orange" Width="{Binding XPath=@Price}"/>
<TextBlock Text="{Binding XPath=@Year}"/>
</Grid>
<TextBlock Text="{Binding XPath=@Price}" Margin="5,0"/>
</StackPanel>
</Grid>
</DataTemplate>
<!--数据源-->
<XmlDataProvider x:Key="Ds" XPath="Units/Unit">
<x:XData>
<Units xmlns="">
<Unit Year="2001" Price="100"/>
<Unit Year="2002" Price="120"/>
<Unit Year="2001" Price="140"/>
<Unit Year="2001" Price="160"/>
<Unit Year="2001" Price="180"/>
<Unit Year="2001" Price="200"/>
<Unit Year="2001" Price="220"/>
</Units>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<StackPanel>
<ListBox ItemsSource="{Binding Source={StaticResource Ds}}" ItemTemplate="{StaticResource MyXmlDataTemplate}"/>
<ComboBox ItemsSource="{Binding Source={StaticResource Ds}}" ItemTemplate="{StaticResource MyXmlDataTemplate}"/>
</StackPanel>
</Window>
显示层级数据的模板是HierarchicaDataTemplate
<?xml version="1.0" encoding="utf-8" ?>
<Data xmlns="">
<Grade Name="一年级">
<Class Name="1班">
<Group Name="A组"/>
<Group Name="B组"/>
<Group Name="C组"/>
<Group Name="D组"/>
</Class>
</Grade>
<Grade Name="二年级">
<Class Name="1班">
<Group Name="A组"/>
<Group Name="B组"/>
<Group Name="C组"/>
<Group Name="D组"/>
</Class>
</Grade>
<Grade Name="三年级">
<Class Name="1班">
<Group Name="A组"/>
<Group Name="B组"/>
<Group Name="C组"/>
<Group Name="D组"/>
</Class>
</Grade>
</Data>
<Window x:Class="TreeView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--数据源-->
<XmlDataProvider x:Key="ds" Source="Data.xml" XPath="Data/Grade"/>
<!--年级模板-->
<HierarchicalDataTemplate DataType="Grade" ItemsSource="{Binding XPath=Class}">
<TextBlock Text="{Binding XPath=@Name}"></TextBlock>
</HierarchicalDataTemplate>
<!--班级模板-->
<HierarchicalDataTemplate DataType="Class" ItemsSource="{Binding XPath=Group}">
<RadioButton Content="{Binding XPath=@Name}" GroupName="gn"></RadioButton>
</HierarchicalDataTemplate>
<!--小组模板-->
<HierarchicalDataTemplate DataType="Group" ItemsSource="{Binding XPath=Student}">
<CheckBox Content="{Binding XPath=@Name}"></CheckBox>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView ItemsSource="{Binding Source={StaticResource ds}}"></TreeView>
</Grid>
</Window>
WPF中的DataTemplate的更多相关文章
- WPF 中的DataTemplate 的嵌套
<Window x:Class="WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xa ...
- 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 ...
随机推荐
- Umbraco(5)-Creating Master Template Part 1(翻译文档)
原文地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/umbraco5-creating-master-template-par ...
- javascript中Math ceil(),floor(),round()三个函数的对比
Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...
- Python 标准库 urllib2 的使用细节[转]
转自[http://zhuoqiang.me/python-urllib2-usage.html] Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节描述的并不清楚,比 ...
- jQuery图片提示和文字提示
图片提示: 效果如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
- OpenFlow概述
OpenFlow名称里面虽然包括“Flow”,但其并不是“又一个流程引擎”,我们认为世界上的流程引擎已经足够多了,每个流程引擎都各有千秋,有的甚至免费,所以我们不需要再做一个流程引擎,我们做OpenF ...
- Table of Contents - CXF
Getting Started A simple JAX-WS service Writing a service with Spring Tools WSDL to Java RESTful Ser ...
- CSS3--实现特殊阴影 (实例)
学习来源:慕课网http://www.imooc.com/view/240 先看效果图↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ HTML结构 <body> <div class=& ...
- [转]JAVA三大框架SSH和MVC
Java—SSH(MVC) JAVA三大框架的各自作用 hibernate是底层基于jdbc的orm(对象关系映射)持久化框架,即:表与类的映射,字段与属性的映射,记录与对象的映射 数据库模型 也就 ...
- win7安装office2007出错被中断-已经解决
觉得雨林木风win7系统本身的office2007不好,但不能卸载,用360强力删除工具,把整个安装的文件夹全部删除,重新用之前能够在另外xp和win7系统成功安装的破解版office2007,安装开 ...