我对状态栏项使用什么命名约定?

时间:2012-09-06 01:43:13

标签: c# .net wpf naming-conventions

使用WPF时经常遇到的一件事就是命名约定。

所以这就是我对XAML的看法:

<StatusBar Grid.Row="2" MinHeight="20" Name="StatusBar">
        <StatusBarItem>
            <Border BorderBrush="Black" BorderThickness=".25,.25,0,0">
                <Border BorderBrush="White" BorderThickness="0,0,.25,.25">
                    <TextBlock Name="StatusBarText" Margin="2,2,2,2" >Ready</TextBlock>
                </Border>
            </Border>
        </StatusBarItem>

        <StatusBarItem>
            <Border BorderBrush="Black" BorderThickness=".25,.25,0,0">
                <Border BorderBrush="White" BorderThickness="0,0,.25,.25">
                    <TextBlock Name="FilePathText" Margin="2,2,2,2" >File Path</TextBlock>
                </Border>
            </Border>
        </StatusBarItem>
    </StatusBar>

TextBlock的内容将是数据绑定。我真的不确定如何命名我的UI元素和属性以避免任何潜在的歧义。

    public string StatusBarText 
   //Maybe StatusText instead of StatusBarText since this 
   //indicates the current status of the application (Ready,Running,Error etc)?
    {
        get { return statusBarText; }
        set
        {
            statusBarText = value;
            NotifyOfPropertyChange(() => StatusBarText);
        }
    }

    public string FilePathText
    {
        get { return filePathText; }
        set
        {
            filePathText = value;
            NotifyOfPropertyChange(() => filePathText);
        }
    }

我的意思是那些属性的名字很好吗?我觉得如果另一个人要查看这些属性名称,他/她无法确定这些字符串是否用于StatusBar文本块。我猜匈牙利的符号可能会解决这个问题,但现在没有多少人认为这是一个好主意。

你有什么建议?

1 个答案:

答案 0 :(得分:1)

如果您正确使用MVVM,控件通常不需要名称,因为它们永远不会被引用。 (只有他们绑定的数据。)

需要名称的唯一控件是您绝对必须在代码隐藏或类似内容中引用的名称,或者可能具有指向它们的相对绑定的内容,这些内容无法依赖于类型。

就命名约定而言,我分别采用了视图/控件的UI / ux命名约定。命名线索只是暗示它是一个控件,而不是控制类型那么具体。这样,可以更改类型以反映业务需求或需求,而无需您重命名引用或留下误导性引用。

相关问题