theSpyCry
theSpyCry

Reputation: 12293

WPF UserControl naming convention question

I'm creating a WPF UserControl with many elements inside. I need to work with them and I need to give them names. I've seen that in some custom controls people are naming elements this way:

PART_name

Should I name my elements like PART_ListBox.. etc? Or what's the purpose of this? Is it to differentiate that these names are part of a UserControl?

Btw my class inhertis directly from UserControl, not from Control.

class MyControl: UserControl {}

Upvotes: 2

Views: 2454

Answers (2)

Jobi Joy
Jobi Joy

Reputation: 50048

PART_ convention is needed only in Custom control templates. As you know that a custom control generally be 'lookless' in nature so the developer developing the control might need to assume some XAML controls present in all the customization of that ControlTemplate. So PART_ is a way to let the person doing the XAML Edit(Giving look to the custom control) know that they need to retain the PART_ named controls in the new control template because the code really depends on those.

In your case it is UserControl(Which means the it is not really a look less control) so you don't need to go with PART_ convention here.

Upvotes: 2

Chris Nicol
Chris Nicol

Reputation: 10396

This is the Microsoft standard for internal parts of a Template/Style. These parts are local to the control, so it would depend what the scope of your element that you are naming is.

As for whether or not to use this standard, my opinion is that because all the generic WPF/Silverlight control templates/styles use this convention I would follow the pack on this one, also from my experience, I like the PART_ naming convention, as I find that local elements stand out well within my templates and styles.

Hope that helps.

Upvotes: 1

Related Questions