2013-04-01 16:25 2188人阅读 评论(0) 收藏 举报
 分类:
.Net(C#)(31)  WPF(25) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

  1. <Window x:Class="TestOfContentControl.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow" Height="350" Width="525">
  5. <StackPanel>
  6. <Button Margin="5" >
  7. <TextBlock Text="Hello" />
  8. </Button>
  9. <Button Margin="5" >
  10. <Image Source="j.png" Width="30" Height="30" />
  11. </Button>
  12. <GroupBox Margin="10" BorderBrush="Gray" >
  13. <GroupBox.Header>
  14. <Image Source="j.png" Width="20" Height="20" />
  15. </GroupBox.Header>
  16. <TextBlock TextWrapping="WrapWithOverflow" Margin="5"
  17. Text="一棵树,一匹马,一头大象和一只鸡在一起,打一种日常用品。"/>
  18. </GroupBox>
  19. </StackPanel>
  20. </Window>
  1. <Window x:Class="TestOfItemsControl.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow" Height="350" Width="525">
  5. <StackPanel>
  6. <ListBox Margin="5" >
  7. <CheckBox x:Name="checkBoxTim" Content="Tim" />
  8. <CheckBox x:Name="checkBoxTom" Content="Tom" />
  9. <CheckBox x:Name="checkBoxBruce" Content="Bruce" />
  10. <Button x:Name="buttonMess" Content="Mess" />
  11. <Button x:Name="buttonOwen" Content="Owen" />
  12. <Button x:Name="buttonVictor" Content="Victor" Click="buttonVictor_Click"/>
  13. </ListBox>
  14. <ListBox x:Name="empLists" >
  15. </ListBox>
  16. </StackPanel>
  17. </Window>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. namespace TestOfItemsControl
  15. {
  16. /// <summary>
  17. /// Interaction logic for MainWindow.xaml
  18. /// </summary>
  19. public partial class MainWindow : Window
  20. {
  21. public MainWindow()
  22. {
  23. InitializeComponent();
  24. }
  25. private void buttonVictor_Click(object sender, RoutedEventArgs e)
  26. {
  27. List<Employee> empList = new List<Employee>()
  28. {
  29. new Employee(){Id=1,Name="Tim",Age = 30},
  30. new Employee(){Id=2,Name="Tom",Age=26},
  31. new Employee(){Id=3,Name="Guo",Age=26},
  32. new Employee(){Id=4,Name="Yan",Age=26},
  33. new Employee(){Id=5,Name="Owen",Age=26},
  34. new Employee(){Id=6,Name="Victor",Age=26}
  35. };
  36. Button btn = sender as Button;
  37. DependencyObject level1 = VisualTreeHelper.GetParent(btn);
  38. DependencyObject level2 = VisualTreeHelper.GetParent(level1);
  39. DependencyObject level3 = VisualTreeHelper.GetParent(level2);
  40. MessageBox.Show(level3.GetType().ToString());
  41. this.empLists.DisplayMemberPath = "Name";
  42. this.empLists.SelectedValuePath = "Id";
  43. this.empLists.ItemsSource = empList;
  44. }
  45. }
  46. public class Employee
  47. {
  48. public int Id { get; set; }
  49. public string Name { get; set; }
  50. public int Age { get; set; }
  51. }
  52. }

WPF(ContentControl和ItemsControl)的更多相关文章

  1. 在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 ...

  2. [WPF自定义控件库]了解如何自定义ItemsControl

    1. 前言 对WPF来说ContentControl和ItemsControl是最重要的两个控件. 顾名思义,ItemsControl表示可用于呈现一组Item的控件.大部分时候我们并不需要自定义It ...

  3. XAML中ContentControl,ItemsControl,DataTemplate之间的联系和区别

    接触XAML很久了,但一直没有深入学习.今天学习了如标题所示的内容,所以来和大家分享一下,或者准确的说是自我回顾一遍. 在XAML中,有两类我们常见的控件,分别是ContentControl和Item ...

  4. [UWP]了解模板化控件(8):ItemsControl

    1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...

  5. 从PRISM开始学WPF(三)Prism-Region?

    从PRISM开始学WPF(一)WPF? 从PRISM开始学WPF(二)Prism? 从PRISM开始学WPF(三)Prism-Region? 从PRISM开始学WPF(四)Prism-Module? ...

  6. 从PRISM开始学WPF(三)Prism-Region-更新至Prism7.1

    [7.1update]在开始前,我们先看下版本7.1中在本实例中的改动. 首先,项目文件中没有了Bootstrapper.cs,在上一篇的末尾,我们说过了,在7.1中,不见推荐使用Bootstrapp ...

  7. [UWP 自定义控件]了解模板化控件(8):ItemsControl

    1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...

  8. WPF核心对象模型-类图和解析

    DispatcherObject是根基类,通过继承该类,可以得到访问创建该对象的UI线程的Dispatcher对象的能力.通过Dispatcher对象,可以将代码段合并入该UI线程执行. Depend ...

  9. WPF DataTemplate與ControlTemplate

    一. 前言     什麼是DataTemplate? 什麼是ControlTemplate? 在stackoverflow有句簡短的解釋 "A DataTemplate, therefore ...

随机推荐

  1. Java 集合 集合与数组之间的转换

    Java 集合 集合与数组之间的转换 @author ixenos 数组转集合 Arrays.asList(T... a) 先给结论:用 Arrays.asList(T... a) 将数组转换成集合 ...

  2. thrift安装笔记

    Thrift源于大名鼎鼎的facebook之手,在2007年facebook提交Apache基金会将Thrift作为一个开源项目,对于当时 的facebook来说创造thrift是为了解决facebo ...

  3. 洛谷-小鱼会有危险吗-BOSS战-入门综合练习2

    题目描述 Description 有一次,小鱼要从A处沿直线往右边游,小鱼第一秒可以游7米,从第二秒开始每秒游的距离只有前一秒的98%.有个极其邪恶的猎人在距离A处右边s米的地方,安装了一个隐蔽的探测 ...

  4. 【Loadrunner】初学Loadrunner——参数化设置(Xml类型)

    不是所有类型的参数都是和XML类型,只有一段标准的XML语句块,而且需要选中整个完整的XML语句块才可以使用XML的参数化.单个变量是不适合XML的参数化的.在选择的时候需要选中XML语句块的起始标签 ...

  5. iphone下元素放在了一个position: fixed的div中无法点击

    网上的说法是这样的: iphone的浏览器有这么一个bug, 当你使用锚定或滚动页面后, 你会发现某些东西不能点击了! 如果你的这个“东西”放在了一个position: fixed的div中, 那么你 ...

  6. sftp配置多用户权限

    sftp配置多用户权限   工作需要,用户上传文件到目录下,用ftp不太安全,选择sftp.让用户在自己的home目录下活动,不能ssh到机器进行操作.   下面开始干活. 查看ssh版本 ssh - ...

  7. android Bind机制(二)

    1.binder通信概述 binder通信是一种client-server的通信结构,    1.从表面上来看,是client通过获得一个server的代理接口,对server进行直接调用:    2 ...

  8. Codeforces Round #375 (Div. 2)A. The New Year: Mee

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  9. 《JS权威指南学习总结--3.1数字》

    3.1数字 内容要点: 一.数字直接量:当一个数字直接出现在JS程序中,我们称之为数字直接量. 二.JS中的算术运算 Math.pow(2,53)      // => 900719925474 ...

  10. Eclipse配置--智能补全

    定位到:Windows→Preferences→Java→Editor→Content Assist 将Auto Activation triggers for java的默认值“.”修改为" ...