“弹出窗口是控制部分” - 什么是“控制部分”在银光中?
我正在尝试使用 Expression Blend 在 Silverlight 中设计组合框的样式。
ComboBox 模板包含四个项目:
ContentPresenterBorder
DisabledVisualElement
FocusVisualElement
Popup
ContentPresenterBorder
和 < code>Popup 包含子元素,并且还有一个小图标,看起来像带有绿色勾号的拼图游戏。将鼠标悬停在该图标上时,我会看到工具提示:
Popup是一个控制部分。
这意味着什么?
I'm trying to style a ComboBox in Silverlight using Expression Blend.
The ComboBox template contains four items:
ContentPresenterBorder
DisabledVisualElement
FocusVisualElement
Popup
Both ContentPresenterBorder
and Popup
contain child elements, and also have a small icon that looks like a jigsaw puzzle piece with a green tick. On mouse-over this icon, I get the tooltip:
Popup is a control part.
What does this mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此博文 解释了各个部分,但实际上它是一个具有预定义类型和名称的元素。假设我想创建一个名为
FancyControl
的新控件。在我的控件内,我需要两个滑块,无论出于何种原因,制作控件的最佳方法是直接访问在代码隐藏中为我的控件创建的Slider
对象。我可以给它们任何旧名称(即“左”和“右”),然后使用
GetTemplatedChild
找到FancyControl.OnApplyTemplate
中的实例。使用任意名称的问题是,如果其他人想要重新设计我的控件,他们不知道滑块需要的名称为“左”和“右”我对工作的控制。Microsoft 使用的约定是为这些元素命名以
PART_
为前缀。因此,现在当有人重新设计我的控件时,他们会立即知道Slider
必须具有相同的名称(即“PART_Left”和“PART_Right”),否则他们可能会失去功能。TemplatePartAttribute 可用于指示有效的部件名称及其相关类型。设计师(例如 Blend)可以使用它来正确检测命名零件。
还值得一提的是,控件的设计方式应该是,如果指定的部分丢失,那么它应该继续以较少的功能工作(即它不应该抛出异常)。
This blog post explains parts, but effectively it's an element with a predefined type and name. Let's say I want to make a new control called
FancyControl
. Inside my control I want two sliders and for whatever reason, the best way for me to make my control is to have direct access to theSlider
objects that are created for my control in my code-behind.I could give them any old name (i.e. "left" and "right"), then find the instances inside
FancyControl.OnApplyTemplate
usingGetTemplatedChild
. The problem with using arbitrary names, is if someone else wants to restyle my control they do not know that theSliders
need to have the names "left" and "right" for my control to work.Microsoft used the convention of giving these elements names prefixed with
PART_
. So now when someone restyles my control, they will immediately know that theSlider
must have the same name (i.e. "PART_Left" and "PART_Right") or else they may lose functionality.The TemplatePartAttribute can be used to indicate the valid part names and their associated type. This can be used by designers, such as Blend, to properly detect named parts.
It is also worth mentioning that controls should be designed in such a way that if a named part is missing, then it should continue to work with less functionality (i.e. it should not throw exceptions).