5 .net wpf controls naming-conventions
它存在一些标准用于WPF中的UI控件的表示法.像匈牙利符号的东西.
例如
<TextBox Name=tbNameOfTextBox/>
<Image Name=imgOfMe/>
<RichTextBox Name="rtbDocument"/>
Run Code Online (Sandbox Code Playgroud)
你用什么样的符号?
我的第二个问题是关于元素中的序列,组织属性.
我有这样的例子:
<ListBox Name="friendsListBox"
ItemsSource="{Binding}"
SelectedItem="Key"
Style="{DynamicResource friendsListStyle}"
PreviewMouseRightButtonUp="ListBox_PreviewMouseRightButtonUp"
PreviewMouseRightButtonDown="ListBox_PreviewMouseRightButtonDown"
Grid.Row="2"
Margin="4,4,4,4"
MouseRightButtonDown="FriendsListBoxMouseRightButtonDown">
Run Code Online (Sandbox Code Playgroud)
要么
<TextBox Name="TbStatus"
Text="{Binding Path=Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource CurveTextBox}"
Grid.Column="1"
TextWrapping="Wrap"
Margin="3,3,3,3" LostFocus="TbStatus_LostFocus" />
Run Code Online (Sandbox Code Playgroud)
在列表框中,我有Name,ItemSource,SelectedItem和som Events等属性.什么适合他们的组织.第一个应该是UI控件的名称,然后是事件,最后是样式属性?
1)控件命名
Cody Gray建议的帖子应足以作为WPF UI元素命名约定
2)事件命名
我更喜欢使用与Visual Studio“ <ControlName> _ <EventName>”相同的约定。当您键入事件名称并点击TAB时,它将为您生成方法。除了在多个控件上使用它之外,没有其他理由花时间重命名它-在这种情况下,您希望为处理程序提供一些通用的描述性名称。
3)属性顺序
我的名字是:名字(如果存在),事件在后。所有其他属性应按其影响进行分组-与外观相关(背景,前景,不透明度等),与布局相关(高度,宽度,匹配度等),等等。在属性列表的顶部和“高度”中不要包含“宽度” ”位于底部。
| 归档时间: |
|
| 查看次数: |
4775 次 |
| 最近记录: |