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 ...
随机推荐
- 可靠通信的保障 —— 使用ACK机制发送自定义信息——ESFramework 通信框架4.0 快速上手(12)
使用ESPlus.Application.CustomizeInfo.Passive.ICustomizeInfoOutter接口的Send方法,我们已经可以给服务端或其它在线客户端发送自定义信息了, ...
- OMCS ——卓尔不群的网络语音视频框架
作为.NET平台上的开发人员,要开发出一个像样视频聊天系统或视频会议系统,非常艰难,这不仅仅是因为.NET对多媒体的支持比较有限,还因为网络语音视频这块涉及到了很多专业方面的技术,而.NET在这些方面 ...
- WTL 设置 SDI 主窗口初始大小的方法
在窗口创建之前添加一段代码 一般窗口创建函数为 wndMain.CreateEx(); 在此函数前添加 1: RECT rect = {x, y, width, height}; 然后将创建窗口函数改 ...
- spring容器启动的加载过程(二)
第六步: public abstract class AbstractApplicationContext extends DefaultResourceLoader implements Confi ...
- Swift-HELP
//获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString
- html5游戏开发框架之lufylegend开源库件学习记录
下载地址http://lufylegend.com/lufylegend 引用 <script type="text/javascript" src="../luf ...
- linux nfs开启
nfs设置: NFS的配置过程很简单.在服务器端中编辑/etc/exports文件,添加如下内容: /home/cotton/data/cotton/zghy 192.168.2.*(rw,s ...
- NSURL访问项目中的文件
最近在研究视频处理,具体为:将一个mp4文件,拖入项目工程中,通过url访问文件. 开始代码如下: NSString *path = [[NSBundle mainBundle]pathForReso ...
- MyBatis 多表联合查询,字段重复的解决方法
MyBatis 多表联合查询,两张表中字段重复时,在配置文件中,sql语句联合查询时使用字段别名,resultMap中对应的column属性使用相应的别名: <resultMap type=&q ...
- hdu 5493 Queue treap实现将元素快速插入到第i个位置
input T 1<=T<=1000 n 1<=n<=100000 h1 k1 h2 k2 ... ... hn kn 1<=hi<=1e9 0<=ki&l ...