博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF ItemsControl ListBox ListView比较
阅读量:6687 次
发布时间:2019-06-25

本文共 3853 字,大约阅读时间需要 12 分钟。

在进行列表信息展示时,WPF中提供多种列表可供选择。这篇博客将对WPF ItemsControl, ListBox, ListView进行比较。

相同点:

1. 这三个控件都是列表型控件,可以进行列表绑定(ItemsSource);

2. 这三个控件均使用ItemsPresenter来展示列表信息;

不同点:

控件层次关系:

:

System.Object

  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ItemsControl

:

System.Object

  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ItemsControl
                System.Windows.Controls.Primitives.Selector
                  System.Windows.Controls.ListBox

ListBox 继承于ItemsControl,增加了一个Selector对象,ItemsControl中的Item是不支持选择的。而ListBox中Item是支持选择,并且可以单选,多选。

:

System.Object

  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ItemsControl
                System.Windows.Controls.Primitives.Selector
                  System.Windows.Controls.ListBox
                    System.Windows.Controls.ListView

ListView继承与ListBox,增加了一个View依赖属性。

ItemsControl是不包含水平和垂直方向的滚动条的。ListBox和ListView有水平和垂直方向滚动条。

ItemControl的样式:

ListBox和ListView的样式基本一样,除了TargetType外,

在项目中如何选择使用这三个控件;

1. 如果列表信息只做展示,但不提供选择功能,可以使用ItemsControl;

2. ListView比ListBox增加了一个View属性。

示例代码:

ItemsControl vs ListBox (Selector)

C#

public class Task    {        public string Name { get; set; }        public int Priority { get; set; }    }    ObservableCollection
_tasks = null; public MainWindow() { InitializeComponent(); _tasks = new ObservableCollection
() { new Task() { Name = "Shopping",Priority = 2 }, new Task() { Name = "Laundry",Priority = 2 }, new Task() { Name = "Email",Priority = 1 }, new Task() { Name = "Writting",Priority = 2 }, new Task() { Name = "Learning",Priority = 2 }, new Task() { Name = "Working",Priority = 2 }, }; DataContext = _tasks; }

运行效果:

ListView View属性的使用

运行效果:

感谢您的阅读,代码点击下载。

转载于:https://www.cnblogs.com/yang-fei/p/4720596.html

你可能感兴趣的文章
有效的java程序片段
查看>>
Java类排序_浅析
查看>>
图文详解如何修改git已提交记录的邮箱?
查看>>
配置SSH
查看>>
storm翻译(2):Concepts
查看>>
Exchange 2013文档之三:Exchange Server 2013在Windows 2012平台下部署
查看>>
Shell获取局域网指定IP地址的MAC和主机名,并插入数据库
查看>>
mysql安装记录文档
查看>>
Vmware /CentOS访问Windows中的文件
查看>>
pg9.5升级 到 pg11 的步骤
查看>>
09可靠消息最终一致性方案2--独立消息服务
查看>>
Linux系统下生成一个指定大小的文件和空间预留
查看>>
LNMP搭建9:Nginx日志切割
查看>>
智慧城市,城市建设规划的风向标!
查看>>
我的友情链接
查看>>
破解XP的登录密码简招
查看>>
(24)Poweshell中的if条件判断
查看>>
IE8 新建会话
查看>>
利用blink CEP实现流计算中的超时统计问题
查看>>
我的友情链接
查看>>