WPF(ContentControl和ItemsControl)



版权声明:本文为博主原创文章,未经博主允许不得转载。
- <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 ...
随机推荐
- NSURLConnection基本使用
一.NSURLConnection的常用类 (1)NSURL:请求地址 (2)NSURLRequest:封装一个请求,保存发给服务器的全部数据,包括一个NSURL对象,请求方法.请求头.请求体.... ...
- dplyr 数据操作 列操作(select / mutate)
在R中,我们通常需要对数据列进行各种各样的操作,比如选取某一列.重命名某一列等. dplyr中的select函数子在数据列的操作上也同样表现了它的简洁性,而且各种操作眼花缭乱. select(.dat ...
- Codeforces Round #366 (Div. 2)_B. Spider Man
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- onkeyup事件
当用户释放键盘按钮时执行Javascript代码. 上代码: <input type="text" id="frame" onkeyup="my ...
- LeetCode OJ 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- wuzhi 五指 伪静态
rewrite ^(.*)list\/([0-9]+)-([0-9]+)\.html$ $1index.php?v=listing&cid=$2&page=$3 last; rewri ...
- tomcat容器启动的启动过程(三)
Catalina的start方法 /** * Start a new server instance. */ public void start() { if (server == null) { l ...
- Sersync同步过滤.svn文件夹
Sersync同步过滤.svn文件夹 <filter start="true"> <exclude expression="(.*).svn(.*)&q ...
- 实现apk 调用framework java JNI中方法
首先整个实现需要有Android源码编译环境.这里我用的是froyo2.2. 1.JNI层--C++代码部分 在目录frameworks/base/core/jni 下创建android_jnidem ...
- UEFI BIOS模式下Windows系统启动过程以及引导文件修复方法
有关UEFI BIOS基础知识的简介,一年前在网易博客做过详细的概述.鉴于某些网友仍然对UEFI下Windows的启动过程不甚了解,虽然网上有各式各样的启动修复工具,但是对于新手来说,如果不明白其中的 ...