相关疑难解决方法(0)

为什么"propdp"代码段不使用nameof运算符作为注册属性的名称?

如果您插入片段propdp,它不会在DepencendyProperty.Register方法的第一个参数中使用nameof运算符作为属性名称,它会创建如下所示的内容:

    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(string), typeof(MyContentControl), new PropertyMetadata(""));
Run Code Online (Sandbox Code Playgroud)

如果你在下一个例子中使用运算符nameof,那么可能会更好:

    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Text.  This enables animation, …
Run Code Online (Sandbox Code Playgroud)

c# dependency-properties code-snippets visual-studio-2015

5
推荐指数
1
解决办法
887
查看次数