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 ...
随机推荐
- input编辑框编辑状态切换
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 修改weblogic中StuckThreadMaxTime参数
your_domain->Environment ->Servers ->your_server->Configuration->Tuning->Stuck Thr ...
- BestCoder Round #85 A B C
本来没有写博客的打算,可是看完了题解感觉这三道题这么水,我却只做出来一道,实在不应该,还是写点东西吧…… A.sum 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出N ...
- JSON.parse()和JSON.stringify()&&traditional(ajax请求)的作用
parse是一个字符串中解析出json对象,如 var str = '{"name":"haizeiwang"}' 结果: JSON.parse(str) na ...
- Nginx正向代理让无法直接上网的机器通过代理上网
Nginx正向代理让无法直接上网的机器通过代理上网 在阿里云平台买了几台ECS.但是只要其中一台开通了公网.由于要初始化系统环境,需要网络安装相关依赖. Nginx正向代理配置: 一.Nginx 正向 ...
- RPM安装gcc gcc-c++扩展
rpm -ivh cpp--.el5.i386.rpm 回车 rpm -ivh kernel-headers--.el5.i386.rpm 回车 rpm -ivh glibc-headers-.i38 ...
- 安卓手机微信页面position: fixed位置错误
今天做项目的时候发现动用position: fixed做弹窗时,用margin-top:50%这样外边距来响应式的控制位置时,在微信里打开页面的弹窗,弹窗在手机上显示的位置和实际上在手机上的位置不一样 ...
- js事件冒泡和捕捉
(1)冒泡型事件:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: div -> body -> document IE 6.0: div ...
- 一个初学者的辛酸路程-了解Python-2
前言 blog花了一上午写的,结果笔记本关机了,没有保存,找不到了,找不到了啊,所以说,你看的每一篇blog可能都是我写了2次以上的--.哎!! 代码改变世界,继续......... Python基础 ...