本文介绍了为什么宣布DependencyProperty成员公开不受保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以这种方式创建DependencyProperty成员:

Why create DependencyProperty member in this way:

public static readonly DependencyProperty DepProperty = DependencyProperty.Register(...);

而不是这样:

protected static readonly DependencyProperty DepProp = DependencyProperty.Register(...);

为什么我们需要CLR包装器时需要从外部使用DevProp成员: / p>

Why do we need to use the DevProp member from outside when we have the CLR "wrappers":

public bool Dep
{
    get { return (bool)GetValue(DepProperty); }
    set { SetValue(DepProperty, value); }
}


推荐答案

,限制性访问修饰符实际上并未提供针对某些API的预期访问保护,因此,除了 public 之外,没有任何必要声明依赖项属性及其标识符字段:

According to MSDN, restrictive access modifiers don't actually provide the intended access protection from certain APIs, so there's no point declaring dependency properties and their identifier fields anything other than public:

无论如何,我将它们公开为 public 并没有任何危害。

It doesn't do any harm exposing them as public anyway, I'd gather.

这篇关于为什么宣布DependencyProperty成员公开不受保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 07:32