As I stated in another post, I access at times controls direct from the code behind. If I do this I name the controls as I do also in ControlTemplates and DataTemplates, I give them the prefix PART_ and after that I precise the name, for example…
<TextBox Name=”PART_UserName” />
Is this against a common WPF naming scheme? Formerly I used the prefix m_ followed by the description…
<TextBox Name=”m_userName” />
.. because in reality its exactly this, but I don’t liked it.
What do you think?
Please note, I don’t want to discuss whether to use MVVM or not. There are situations I don’t care about.
The pattern
PART_<name>is used when you write custom controls that can be retemplated. These are the names of mandatory parts of the template, without which the control cannot work. Such names are usually declared with a[TemplatePart]attribute in C# code :So unless you’re writing a control template, there’s no reason to use that naming pattern. Just name your controls whatever you like, as long as it makes sense for you.