Wpf 如何确定依赖项属性是否绑定到只读属性?

Wpf 如何确定依赖项属性是否绑定到只读属性?,wpf,binding,dependency-properties,Wpf,Binding,Dependency Properties,我定义了一个用户控件和一个依赖属性(称为:Text)。 现在我想知道文本的绑定属性是否为只读?(在代码隐藏中) 我在BindingExpression中找不到条目 有人能帮我吗?例如,我们可以制作这样的东西: // create some control var elem = new FrameworkElement(); // create context for control elem.DataContext = new TestClass(); // create binding var

我定义了一个用户控件和一个依赖属性(称为:Text)。 现在我想知道文本的绑定属性是否为只读?(在代码隐藏中)

我在BindingExpression中找不到条目


有人能帮我吗?

例如,我们可以制作这样的东西:

// create some control
var elem = new FrameworkElement();
// create context for control
elem.DataContext = new TestClass();
// create binding
var bind = elem.SetBinding(UIElement.AllowDropProperty, "ReadOnlyBool");
// we can resolve property
var pi = bind.ResolvedSource.GetType().GetProperty(bind.ResolvedSourcePropertyName);
// and check if it writeable
var isReadOnly = pi.CanWrite;
并不是每个BindingExpression都有ResolvedSource和/或ResolvedSourcePropertyName,所以,我想,这就是为什么我们没有关于resolved属性的信息的原因

背景:

public class TestClass : DependencyObject
{
    public static readonly DependencyPropertyKey ReadOnlyBoolProperty =
        DependencyProperty.RegisterReadOnly("ReadOnlyBool", typeof (bool), typeof (TestClass),
            new PropertyMetadata());

    public bool ReadOnlyBool => (bool) GetValue(ReadOnlyBoolProperty.DependencyProperty);
}

您将无法创建到只读属性的双向或单向ToSource绑定。那么你的观点是什么呢?我想知道如何设置内部文本编辑的只读标志。这是一部分,如果你有办法解决我的其他问题,请帮助。这没有帮助。在双向绑定的情况下,该模式是默认模式。