When working with WPF or Silverlight, how should one use control naming conventions? Do you name the controls in XAML markup? I have seen samples of projects at codeplex with control names such as "selectButton" or "btnSelect". What would you recommend?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Microsoft has guidelines published here on their web site. The bottom line is that Hungarian naming conventions are out.
To make this more clear, Microsoft has dropped Hungarian notation from all of their naming conventions, including UI elements. HOWEVER, MS has not documented any recommendations for UI elements. There are lots of links out there that note this and offer their suggestions but the bottom line is that with UI elements, you're on your own. Example link.
In our standard we've dropped Hungarian notation and are using explicit naming, meaning a button called OK would be named ButtonOK, a textblock called Comments would be TextblockComments. The downside is that names can get kind of long, the positive is that EVERYONE knows exactly what the element is.
As long as you establish what works for you and use that standard consistently, you can't go wrong.
I usually dont name my controls in XAML, as it would be, most of the time, unused considering everything is set or controlled through bindings. Source : Pete Brown
I don't know about XAML but for regular old ASP.NET the conventions I've seen are:
Not sure which I prefer, honestly. I used to see a lot of code like #2 but reversed (e.g. FirstNameTex, StateDropdown, AcceptsTermsCheck) but I like the other way since it groups related controls together.