"PART_ … "

If you’ve done any digging into WPF control templates, you’ve likely come across an element or two called “PART_[something].”  These guys are scattered throughout the default control styles and are also widely used in SimpleStyles.  You might be wondering what it means and what it does.

So, here’s the skinny: “PART_” is just a naming convention.  It means that the control expects an element with that name to exist in the template and will be looking for it.  Think of it as a way to flag that element as important and an indication that the name shouldn’t change. The control could be looking for that element for a variety of reasons.  A common example is to add an event handler. 

In fact, Any time the control needs to interact directly with a “part” of its template, the “official” best practice is to use the “PART_” naming convention.  The other part of that best practice, though, is that things should “fail gracefully” when that element isn’t available.  Obviously, some parts matter more than others and a missing part might mean missing functionality, but things shouldn’t blow up (exceptions, etc.). 

This is important for a number of reasons, but especially because it is common for elements to be missing while a template author is mid-authoring.  This is especially true in a tool like Expression Interactive Designer. 

The official manifesto on these kinds of best practices can be found here, although it looks like the updated version with the “PART_” convention hasn’t made its way into the SDK (that may have been my bad).

In the meantime, if you’re authoring templates this should help to clarify things a little.  I don’t think anyone has documented the complete list of “PART_” parts, but I believe they are all represented in SimpleStyles.  Also, if you’re building controls, it would be a great idea to follow this convention whenever possible.

3 Comments

Mike Brown / OCT 15 2006

I had noticed this pattern and have been using it with my custom controls. I think that named elements are as much a part of the api of a control as its public members.

I noticed that the TemplatePart attribute finally has documentation to explain its purpose. I assume that cider and expression will use the attribute if present to help template designers verify that their template will work with the control.

Richard / DEC 14 2006

hello, just watchd the session video of wpf from mix06 and very interested to attend mix07.

First of all, great introduction to wpf dude! it was very understable to people like me who cant really pick up that much when presented with a theoretical,programming approach for a technology. I develop simple flash banners for a company but i would be the designer type because i havent gone deeper to a.s. programming.

Having said that, Im looking forward to wpf and wpf/e esp. in way that is very attractive while dynamic for designers like me. I would assume you guys want to achieve that with the expression suite.

I have a major major request(if its possible).i like the asp.net video tutorial site coz it really pushed my learning from 0-beginner or smething like that. so my request is, can you guys put up video tutorials and list of pc requirements in order for people like me to get a very stair like learning process who doesnt have time going through buttom programming resources?

personally, i would like to knw what will i need to develop a website from scratch with wpf/e technology and i would really appreciate it if someone put up a video creating a very simple data list from a query using visual studio and bind the data to put into a xaml box drawn from expression and having a little effect like movements.maybe a top ten list data with an image attached on side floating or smething.

i think a video in a designers approach can open gates for some people who wants to begin executing ideas.

thanks a lot!