WPF(ContentControl和ItemsControl)
WPF(25) 
版权声明:本文为博主原创文章,未经博主允许不得转载。
- <Window x:Class="TestOfContentControl.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">
- <StackPanel>
- <Button Margin="5" >
- <TextBlock Text="Hello" />
- </Button>
- <Button Margin="5" >
- <Image Source="j.png" Width="30" Height="30" />
- </Button>
- <GroupBox Margin="10" BorderBrush="Gray" >
- <GroupBox.Header>
- <Image Source="j.png" Width="20" Height="20" />
- </GroupBox.Header>
- <TextBlock TextWrapping="WrapWithOverflow" Margin="5"
- Text="一棵树,一匹马,一头大象和一只鸡在一起,打一种日常用品。"/>
- </GroupBox>
- </StackPanel>
- </Window>
- <Window x:Class="TestOfItemsControl.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">
- <StackPanel>
- <ListBox Margin="5" >
- <CheckBox x:Name="checkBoxTim" Content="Tim" />
- <CheckBox x:Name="checkBoxTom" Content="Tom" />
- <CheckBox x:Name="checkBoxBruce" Content="Bruce" />
- <Button x:Name="buttonMess" Content="Mess" />
- <Button x:Name="buttonOwen" Content="Owen" />
- <Button x:Name="buttonVictor" Content="Victor" Click="buttonVictor_Click"/>
- </ListBox>
- <ListBox x:Name="empLists" >
- </ListBox>
- </StackPanel>
- </Window>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace TestOfItemsControl
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void buttonVictor_Click(object sender, RoutedEventArgs e)
- {
- List<Employee> empList = new List<Employee>()
- {
- new Employee(){Id=1,Name="Tim",Age = 30},
- new Employee(){Id=2,Name="Tom",Age=26},
- new Employee(){Id=3,Name="Guo",Age=26},
- new Employee(){Id=4,Name="Yan",Age=26},
- new Employee(){Id=5,Name="Owen",Age=26},
- new Employee(){Id=6,Name="Victor",Age=26}
- };
- Button btn = sender as Button;
- DependencyObject level1 = VisualTreeHelper.GetParent(btn);
- DependencyObject level2 = VisualTreeHelper.GetParent(level1);
- DependencyObject level3 = VisualTreeHelper.GetParent(level2);
- MessageBox.Show(level3.GetType().ToString());
- this.empLists.DisplayMemberPath = "Name";
- this.empLists.SelectedValuePath = "Id";
- this.empLists.ItemsSource = empList;
- }
- }
- public class Employee
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public int Age { get; set; }
- }
- }
WPF(ContentControl和ItemsControl)的更多相关文章
- 在WPF中的ItemsControl中使用事件和命令(Using events and Commands within ItemsControl in WPF)
Say I have a standard WPF ItemsControl bound to an ObservableCollection of "Dog" objects l ...
- [WPF自定义控件库]了解如何自定义ItemsControl
1. 前言 对WPF来说ContentControl和ItemsControl是最重要的两个控件. 顾名思义,ItemsControl表示可用于呈现一组Item的控件.大部分时候我们并不需要自定义It ...
- XAML中ContentControl,ItemsControl,DataTemplate之间的联系和区别
接触XAML很久了,但一直没有深入学习.今天学习了如标题所示的内容,所以来和大家分享一下,或者准确的说是自我回顾一遍. 在XAML中,有两类我们常见的控件,分别是ContentControl和Item ...
- [UWP]了解模板化控件(8):ItemsControl
1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...
- 从PRISM开始学WPF(三)Prism-Region?
从PRISM开始学WPF(一)WPF? 从PRISM开始学WPF(二)Prism? 从PRISM开始学WPF(三)Prism-Region? 从PRISM开始学WPF(四)Prism-Module? ...
- 从PRISM开始学WPF(三)Prism-Region-更新至Prism7.1
[7.1update]在开始前,我们先看下版本7.1中在本实例中的改动. 首先,项目文件中没有了Bootstrapper.cs,在上一篇的末尾,我们说过了,在7.1中,不见推荐使用Bootstrapp ...
- [UWP 自定义控件]了解模板化控件(8):ItemsControl
1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...
- WPF核心对象模型-类图和解析
DispatcherObject是根基类,通过继承该类,可以得到访问创建该对象的UI线程的Dispatcher对象的能力.通过Dispatcher对象,可以将代码段合并入该UI线程执行. Depend ...
- WPF DataTemplate與ControlTemplate
一. 前言 什麼是DataTemplate? 什麼是ControlTemplate? 在stackoverflow有句簡短的解釋 "A DataTemplate, therefore ...
随机推荐
- bzoj1336: [Balkan2002]Alien最小圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...
- 2016弱校联盟十一专场10.2——Floyd-Warshall
题目链接:Floyd-Warshall 题意: 给你n个点,m条边,100>m-n>0,现在有q个询问,问你任意两点的最短距离,题目保证每条边都被连接,每条边的距离为1 题解: 首先我们可 ...
- From windows live writer
天线数据长度: 4*14*9664*4 = 2164736 信道估计长度: 614400 均衡: 12*1200*4 = 57600
- C++ 中 delete 和 delete[] 的区别
一直对 C++ 中 delete 和 delete[] 的区别不甚了解,今天遇到了,上网查了一下,得出了结论.做个备份,以免丢失. C++ 告诉我们在回收用 new 分配的单个对象的内存空间时用 de ...
- Openjudge-计算概论(A)-与7无关的数
描述: 一个正整数,如果它能被7整除,或者它的十进制表示法中某一位上的数字为7,则称其为与7相关的数.现求所有小于等于n(n < 100)的与7无关的正整数的平方和. 输入输入为一行,正整数n( ...
- js 禁止重复提交
/*分享按钮*/ var flag = true; $(".recommed a").click(function() { if (flag == true) { getServe ...
- TortoiseGit保存用户名及密码
保存密码方式如下,需要setting中填写自己的名字,Email地址,并在.gitconfig中 [credential] 中设置helper = store
- JPA 系列教程11-复合主键-2个@Id
复合主键 指多个主键联合形成一个主键组合 需求产生 比如航线一般是由出发地及目的地确定,如果要确定唯一的航线就可以用出发地和目的地一起来表示 ddl语句 CREATE TABLE `t_airline ...
- shell编程之sed
一.sed (Stream Editor) 1.定位行:sed -n '12,~3p' pass #从第12行开始,直到下一个3的倍数行(12-15行)sed -n '12,+4p' pass #从第 ...
- maven下载,安装与eclipse中maven配置
1.maven下载.安装与环境变量配置 http://blog.csdn.net/jiuqiyuliang/article/details/45390313 2.Eclipse中maven的配置 ht ...