源码工作室

目标:通俗的语言说出通俗的技术
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

WPF中template的区别

Posted on 2008-12-04 13:30  源码工作室  阅读(664)  评论(0编辑  收藏  举报

As you can tell from the above figure, there are 4 kinds of Templates available within WPF.

1. ControlTemplate - You use this, when you want to completely redefine the visual appearance of any control. Say, you don't want a radiobutton to look like a radiobutton - you want it to look like a smiley instead. Smiling means Checked, and Frowning means Unchecked. You could easily acheive this using ControlTemplate.

2. ItemsPanelTemplate - Is a rather simple kind of template, it lets you control the appearance of the "ItemsPanel" property defined by "ItemsControl" on elements such as ListBox or ComboBox.

3. DataTemplate - is probably the most common kind of template you will use. It lets you change how "Content" is rendered on any control. So if you have an object called "Customer" and you want to define a standard look and feel for "Customer" - you'd use DataTemplate.

3.a. HierarchicalDataTemplate - is a class that is a DataTemplate that is very well suited to hierarchical data.