详解Silverlight Treeview的HierarchicalDataTemplate使用
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
8 <Grid x:Name="LayoutRoot">
9 <ListBox>
10 <sys:String>树型演示1</sys:String>
11 <sys:String>树型演示2</sys:String>
12 <sys:String>树型演示3</sys:String>
13 <sys:String>树型演示4</sys:String>
14 <sys:String>树型演示5</sys:String>
15 </ListBox>
16 </Grid>
17 </UserControl>
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
8 <Grid x:Name="LayoutRoot">
9 <ListBox>
10 <ListBox.ItemTemplate>
11 <DataTemplate>
12 <TextBlock Foreground="Blue" Text="{Binding}" />
13 </DataTemplate>
14 </ListBox.ItemTemplate>
15 <sys:String>树型演示1</sys:String>
16 <sys:String>树型演示2</sys:String>
17 <sys:String>树型演示3</sys:String>
18 <sys:String>树型演示4</sys:String>
19 <sys:String>树型演示5</sys:String>
20 </ListBox>
21 </Grid>
22 </UserControl>
23
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
8 <Grid x:Name="LayoutRoot">
9 <ListBox>
10
11
12 <ListBoxItem Content="树型演示1">
13 <ListBoxItem.ContentTemplate>
14 <DataTemplate x:Name="myTemplate">
15 <TextBlock Foreground="Blue" Text="{Binding}" />
16 </DataTemplate>
17 </ListBoxItem.ContentTemplate>
18 </ListBoxItem>
19 <ListBoxItem Content="树型演示2" ContentTemplate="{Binding ElementName=myTemplate}" />
20 <ListBoxItem Content="树型演示3" ContentTemplate="{Binding ElementName=myTemplate}" />
21 <ListBoxItem Content="树型演示4" ContentTemplate="{Binding ElementName=myTemplate}" />
22 <ListBoxItem Content="树型演示5" ContentTemplate="{Binding ElementName=myTemplate}" />
23 </ListBox>
24 </Grid>
25 </UserControl>
26
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
8 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
9 <Grid x:Name="LayoutRoot">
10 <Controls:TreeView>
11 <sys:String>树形演示1</sys:String>
12 <sys:String>树形演示2</sys:String>
13 <sys:String>树形演示3</sys:String>
14 </Controls:TreeView>
15 </Grid>
16 </UserControl>
17
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
8 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
9 <Grid x:Name="LayoutRoot">
10 <Controls:TreeView>
11 <Controls:TreeView.ItemTemplate>
12 <DataTemplate>
13 <TextBlock Foreground="Green" Text="{Binding}" />
14 </DataTemplate>
15 </Controls:TreeView.ItemTemplate>
16 <sys:String>树型演示1</sys:String>
17 <sys:String>树型演示2</sys:String>
18 <sys:String>树型演示3</sys:String>
19 </Controls:TreeView>
20 </Grid>
21 </UserControl>
22
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6 xmlns:sys="clr-namespace:System;assembly=mscorlib"
7 xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
8 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
9 <Grid x:Name="LayoutRoot">
10 <Controls:TreeView>
11 <Controls:TreeViewItem Header="树型演示1">
12 <Controls:TreeViewItem.HeaderTemplate>
13 <DataTemplate x:Name="myTemplate">
14 <TextBlock Foreground="Green" Text="{Binding}" />
15 </DataTemplate>
16 </Controls:TreeViewItem.HeaderTemplate>
17 </Controls:TreeViewItem>
18 <Controls:TreeViewItem Header="树型演示2" HeaderTemplate="{Binding ElementName=myTemplate}" />
19 <Controls:TreeViewItem Header="树型演示3" HeaderTemplate="{Binding ElementName=myTemplate}" />
20 </Controls:TreeView>
21 </Grid>
22 </UserControl>
23
2 {
3 public Country()
4 {
5 Privinces = new ObservableCollection<Province>();
6 }
7
8 public string Name { get; set; }
9 public ObservableCollection<Province> Privinces { get; set; }
10 }
11
12 public class Province
13 {
14 public Province()
15 {
16 Citys = new ObservableCollection<City>();
17 }
18
19 public string Name { get; set; }
20 public ObservableCollection<City> Citys { get; set; }
21 }
22
23 public class City
24 {
25 public string Name { get; set; }
26 }
2 new Country {
3 Name = "中国",
4 Privinces = { new Province
5 {
6 Name="山东省",
7 Citys = {
8 new City { Name = "济南市" },
9 new City { Name= "淄博市" }
10 }
11 },
12 new Province
13 {
14 Name="广东省",
15 Citys = {
16 new City { Name = "广州市" },
17 new City { Name= "佛山市" }
18 }
19 }
20 }
21 },
22 new Country {
23 Name = "加拿大",
24 Privinces = { new Province
25 {
26 Name="哥伦比亚省",
27 Citys = {
28 new City { Name = "温哥华市" },
29 new City { Name= "维多利亚市" }
30 }
31 },
32 new Province
33 {
34 Name="阿尔伯塔省",
35 Citys = {
36 new City { Name = "埃德蒙顿市" },
37 new City { Name= "卡尔加里市" }
38 }
39 }
40 }
41 }
42 };
2 <Controls:TreeView.ItemTemplate>
3 <DataTemplate>
4 <TextBlock Text="{Binding Name}" />
5 </DataTemplate>
6 </Controls:TreeView.ItemTemplate>
7 </Controls:TreeView>
2 <Controls:TreeView.ItemTemplate>
3 <common:HierarchicalDataTemplate>
4 <TextBlock Text="{Binding Name}" />
5 </common:HierarchicalDataTemplate>
6 </Controls:TreeView.ItemTemplate>
7 </Controls:TreeView>
8
2 <common:HierarchicalDataTemplate x:Key="CityTemplate">
3 <StackPanel>
4 <TextBlock Text="{Binding Name}"/>
5 </StackPanel>
6 </common:HierarchicalDataTemplate>
7 <common:HierarchicalDataTemplate x:Key="ProvinceTemplate" ItemsSource="{Binding Citys}" ItemTemplate="{StaticResource CityTemplate}">
8 <StackPanel>
9 <TextBlock Text="{Binding Name}" Foreground="Green"/>
10 </StackPanel>
11 </common:HierarchicalDataTemplate>
12 <common:HierarchicalDataTemplate x:Key="CountryTemplate" ItemsSource="{Binding Privinces}" ItemTemplate="{StaticResource ProvinceTemplate}">
13 <TextBlock Text="{Binding Name}" Foreground="Blue"/>
14 </common:HierarchicalDataTemplate>
15 </UserControl.Resources>
本文转自
冷秋寒 51CTO博客,原文链接:http://blog.51cto.com/kevinfan/243767 ,如需转载请自行联系原作者
详解Silverlight Treeview的HierarchicalDataTemplate使用相关推荐
- 图文详解Silverlight访问MSSQL数据库
在银光中国网(SilverlightChina.Net)有一篇"Silverlight与常用数据库互操作系列"文章,其中介绍了使用Silverlight存取不同数据库的方法和步骤. ...
- 完全详解--Silverlight 下载文件
1:假设服务器端有文件test.rar:对应的地址是:http://localhost:34270/ClientBin/test.rar: 2:Silverlight要下载这个文件的方式很简单:使用H ...
- Silverlight实用窍门系列:54.详解Silverlight中的矩阵变换MatrixTransform,实现其余各种变换【附带实例源码】...
在Silverlight中的MatrixTransform矩阵变换相对上篇文章所述的变换较复杂一些,但这种变换也更灵活. MatrixTransform的实质:让需要变换的元素上的每一个像素点*矩阵得 ...
- [Winodows Phone 7控件详解]Silverlight toolkit for Windows Phone 7.1控件-3
2.ToggleSwitch 这个开关控件,是windows phone7独有的,Silverlight 没有实现这个控件.这个控件有两个状态Checked 和Unchecked. <Grid ...
- [Winodows Phone 7控件详解]Silverlight toolkit for Windows Phone 7.1控件-5
11年11月初,微软的silverlight toolkit for phone又放出四个新控件,这四个控件使用都要比之前的复杂,并且很有用. 6.AutoCompleteBox 这个控件很像ajax ...
- python treeview控件使用详解,python Treeview使用笔记 1
先贴代码,python2.7 #!/usr/bin/env python # -*- coding:utf-8 -*- import ttk from Tkinter import * class t ...
- java treeview使用详解_Javafx Treeview项目操作事件
我正在尝试使用treeView创建菜单.这是我第一次使用treeView,并且已经在多个网站上进行了阅读. 我在进行动作事件时遇到一些问题.我想要做的基本上是在用户单击树形视图中的某个节点时触发并发生 ...
- 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox
[索引页] [源码下载] 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 详解ListBox 作者:webabcd 介绍 Silverlight 2.0 详解DataG ...
- 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器...
[索引页] [×××] 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器 作者:webabcd 介绍 Silverlight 2.0 ...
最新文章
- 东财在线计算机第一套作业,东财在线21春《计算机网络基础》第一套作业题目及答案...
- 我们眼中的2015年互联网10大产品事件
- 【CyberSecurityLearning 4】NTFS安全权限及文件共享服务器
- android记账软件开发源代码_如何开发直播软件?直播软件开发的具体流程有哪些?...
- 在spring boot中3分钟上手RPC框架Dubbo
- runTime动态给类添加属性
- 上海java工作经验与薪资_Java硕士京东工作1年,跳槽后他期望薪资26K,大家感觉他可以吗...
- 网页上的html表格导出excel表格,网页表格导出至Excel
- python参考手册下载_Python中文手册【Word版 】
- 常见MFC UI界面库
- 前端JS xxxx年xx月xx日转换成页面时间组件xxxx-xx-xx格式
- 2019最新《后盾网向军0基础学PHP教程》
- python cox模型_Forest plot(森林图) | Cox生存分析可视化
- delphi 应用程序开发工具
- ENSP中ACL,NAT配置
- 沟通的艺术:看人入里,看出人外 - part 1
- arduino/mixly红外发射接收模块
- 【性能测试】性能测试指标TPS(Transaction per Second)
- PCI总线协议(一)
- 红外对管应该如何选择比较好
热门文章
- OpenCV下车牌定位算法实现代码
- java三维滑雪,第六章 三维数据空间分析方法.ppt
- php easyui tree 结构,EasyUI Tree树组件无限循环的解决方法
- matlab 线模式密度,环形腔窄线宽光纤激光器的研究
- java程序ssh置顶_使用shell脚本启动远程(SSH)Java应用程序不会返回本地提示
- tomcat端口号被占用怎么解决_电脑C盘空间不够用怎么办?Win7解决C盘占用空间大的3个方法!...
- python图像相似度识别_一个用SIFT特征比较图像相似度的python小程序
- Java项目:网上图书商城系统(java+SSM+Jsp+MySQL+Redis+JWT+Shiro+RabbitMQ+EasyUI)
- Java项目:清新论坛系统(java+SSM+mysql+maven+tomcat)
- 【java】兴唐第二十九节课作业