什么是ContentControl中和内容presenter之间的区别是什么? [英] What's the difference between ContentControl and ContentPresenter?
问题描述
我不知道什么时候我应该用内容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 DataTemplate
s. 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):
- 在
控件模板
使用内容presenter
- 之外
控件模板
(包括的DataTemplate
内外模板)尽量不要使用其中任何一个,如果你需要到,您必须preFER内容presenter
- 在子类
ContentControl中
如果要创建一个自定义的无外观的控制主机内容,你不能获得相同的结果,通过改变现有控件的模板(应该是极为罕见)。
- Inside
ControlTemplate
useContentPresenter
- Outside of
ControlTemplate
(includingDataTemplate
and outside templates) try not to use any of them, if you need to, you must preferContentPresenter
- 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屋!