命名用户控件。习俗?
这样你就有了一个用户控件。您想要绑定到它的一些依赖属性,因此您需要指定一个 x:Name 才能使用它。
你不能这样做......
<UserControl x:Class="WpfApplication1.UserControl1" x:Name="UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid />
</UserControl>
因为成员名称不能与其封闭类型相同。
所以你需要选择其他东西......但是这里有什么好的约定呢?把任意的东西坚持到最后? “用户控制1用户控制”?称之为“根”?使用不同的大小写“userControl1”?
你们都做了什么选择?
我知道这确实很小,但我尝试非常仔细地命名元素,一致性对我来说很重要。
So you've got a usercontrol. You would like to bind to some of its dependency properties, so you need specify an x:Name in order to use it.
You can't do this...
<UserControl x:Class="WpfApplication1.UserControl1" x:Name="UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid />
</UserControl>
...because member names cannot be the same as their enclosing type.
So you need to pick something else... but what's a good convention to go for here? Stick something arbitrary on to the end? "UserControl1UserControl"? Call it "Root"? Use a different case "userControl1"?
What choices have you guys been making?
I know this is really minor, but I try to name elements very carefully and consistency is important to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按照您为 XAML 文件命名的方式对其进行命名。
Foo.xaml:
Name it however you named the XAML file.
Foo.xaml:
具有描述性;保持一致。
换句话说,只要选择一些东西并坚持下去。
Be descriptive; be consistent.
In other words, just pick something and stick to it.
这些名称最终会成为类中的字段,因此我只使用标准字段命名约定。如果它是根级控件,我总是将其称为“_root”:
These names end up as fields in your class, so I just use standard field naming conventions. And if it's the root-level control, I always call it "_root":