什么是ContentControl中和内容presenter之间的区别是什么? [英] What's the difference between ContentControl and ContentPresenter?

查看:1327
本文介绍了什么是ContentControl中和内容presenter之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么时候我应该用内容presenter 而不是 ContentControl中(和副反之亦然)。目前,我用我的的DataTemplate 取值 ContentControl中 pretty的所有的时间。当将内容presenter 是一个更好的选择吗?为什么?

I'm not sure when I should use ContentPresenter instead of ContentControl (and vice-versa). At the moment, I'm using ContentControl pretty much all the time in my DataTemplates. When would ContentPresenter be a better choice? and why?

我读过 http://www.beacosta.com/blog/?m=200611 但我还是不明白,当/为什么我会选择一个比其他。

I've read http://www.beacosta.com/blog/?m=200611 but I still don't get when/why I would choose one over the other.

推荐答案

ContentControl中是包含其他元素和有控制的基类内容 - 属性(例如,按钮)。

ContentControl is a base class for controls that contain other elements and have a Content-property (for example, Button).

内容presenter 用于内部控制的模板来显示内容。

ContentPresenter is used inside control templates to display content.

ContentControl中,直接使用时(它应该被用来作为基类),具有使用内容presenter来显示它的内容的控制模板。

ContentControl, when used directly (it's supposed to be used as a base class), has a control template that uses ContentPresenter to display it's content.

编辑:我的经验法则(不适用于所有的情况下,使用你的判断):

My rules of thumb (not applicable in every case, use your judgment):

  1. 控件模板使用内容presenter
  2. 之外控件模板(包括的DataTemplate 内外模板)尽量不要使用其中任何一个,如果你需要到,您必须preFER 内容presenter
  3. 在子类 ContentControl中如果要创建一个自定义的无外观的控制主机内容,你不能获得相同的结果,通过改变现有控件的模板(应该是极为罕见)。
  1. Inside ControlTemplate use ContentPresenter
  2. Outside of ControlTemplate (including DataTemplate and outside templates) try not to use any of them, if you need to, you must prefer ContentPresenter
  3. Subclass ContentControl if you are creating a custom "lookless" control that host content and you can't get the same result by changing an existing control's template (that should be extremely rare).

这篇关于什么是ContentControl中和内容presenter之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆