Controltemplate datatemplate
DataTemplate ControlTemplate
-
we can search many posts about this topic. some valuable link: DataTemplate和ControlTemplate的关系,
-
we can see some definition about ControlTemplate, DataTemplate, HierarchicalDataTemplate
2.1. A ControlTemplate is used to define/change the way a class derived from Control looks, such as Buttons, ListBox, ScrollBar. However, some "Controls" you use are not derived from Control: Best example is the TextBlock class. The TextBlock cannot have a ControlTemplate.
ControlTemplate is connected to the Template property of the Control, we can set it directly to the property.
2.2 DataTemplate is closelly linked with the “Content” in WPF. Certain controls are made to display "Content". Content can be anything, such as Image, Text, Object.... in fact, it is defined as an "object" type. The DataTemplate simply defines how a particular content (or content type) is meant to be displayed.
DataTemplate is used to display Content of a Control, the Relative property is CellTemplate,ContentTemplate,ItemTemplate.
2.3. HierarchicalDataTemplate is an extension of DataTemplate with an additional ItemSource property. It is used to render hierarchical data in controls like treeview or menu.
Example: Usually, a string is displayed using a simple TextBlock... However, if you want a custom text layout, decoration, alignement, ... you would need to define an Alternate DataTemplate. -
the relationship of these concept.
Control类型
- Template属性 (ControlTemplate类型)
- ContentPresenter
- ContentTemplate (DataTemplate类型)
ContentControl类型
- Template属性 (ControlTemplate类型) 继承自Control
- ContentTemplate (DataTemplate类型)
ItemsControl类型
- Template属性 (ControlTemplate类型) 继承自Control
- ItemsPanel属性 (ItemsPanelTemplate类型) 指定布局容器
- ItemTemplate属性 (DateTemplate类型) 每个Item的Template
ListBox controltemplate Datatemplate.
- ListBox.template : controltemplate
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构