相关疑难解决方法(0)

C#GUI命名约定的最佳实践?

GUI,无论是用WinForms还是XAML编写,似乎在我看到的项目之间具有最广泛的命名约定.对于一个TextBox人的名字的简单,我已经看到了各种命名约定:

TextBox tbName      // Hungarian notation
TextBox txtName     // Alternative Hungarian
TextBox NameTextBox // Not even camelCase
TextBox nameTextBox // Field after field with TextBox on the end
TextBox TextBoxName // Suggested in an answer...
TextBox textBoxName // Suggested in an answer...
TextBox uxName      // Suggested in an answer...
TextBox name        // Deceptive since you need name.Text to get the real value
TextBox textBox1    // Default name, as bad as you can get
Run Code Online (Sandbox Code Playgroud)

我通常会遵守所有.cs文件的StyleCop规则,并且看到其他人也这样做,但GUI往往会违反这些规则或变化很大.我没有看到任何专门引用GUI元素的Microsoft指南,而不仅仅是普通变量,甚至是在控制台应用程序之外应用的示例.

在GUI中命名元素的最佳实践是什么?

c# user-interface naming-conventions winforms

69
推荐指数
4
解决办法
4万
查看次数

textBoxEmployeeName与employeeNameTextBox

您使用哪种命名约定?为什么?

我喜欢使用employeeNameTextBox,因为:

  • 从英语角度来看,这似乎更自然.
  • 我发现用Intellisense查找更容易.
  • 该约定类似于用于事件(MouseClickEvent,MouseClickEventHandler)和依赖项属性(VisiblityProperty)的约定.

注意:我使用的是全名而不是缩写(例如"tb"),因为它符合MS的命名约定,即避免使用缩写.

http://msdn.microsoft.com/en-us/library/ms229045.aspx

wpf naming-conventions hungarian-notation winforms

13
推荐指数
1
解决办法
6344
查看次数