Ответ 1
Это легко, на самом деле (через RegisterReadOnly):
public class OwnerClass : DependencyObject // or DependencyObject inheritor
{
private static readonly DependencyPropertyKey ReadOnlyPropPropertyKey
= DependencyProperty.RegisterReadOnly("ReadOnlyProp", typeof(int), typeof(OwnerClass),
new FrameworkPropertyMetadata((int)0,
FrameworkPropertyMetadataOptions.None));
public static readonly DependencyProperty ReadOnlyPropProperty
= ReadOnlyPropPropertyKey.DependencyProperty;
public int ReadOnlyProp
{
get { return (int)GetValue(ReadOnlyPropProperty); }
protected set { SetValue(ReadOnlyPropPropertyKey, value); }
}
//your other code here ...
}
Вы используете ключ только при установке значения в частном/защищенном/внутреннем коде. Благодаря защищенному сетевому устройству ReadOnlyProp
это прозрачно для вас.