I’m trying to style a ComboBox in Silverlight using Expression Blend.
The ComboBox template contains four items:
ContentPresenterBorderDisabledVisualElementFocusVisualElementPopup
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?
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 theSliderobjects 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.OnApplyTemplateusingGetTemplatedChild. The problem with using arbitrary names, is if someone else wants to restyle my control they do not know that theSlidersneed 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 theSlidermust 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).