C# 绑定中的共享依赖项属性更新问题
我有一个只读依赖属性,它在两个WPF类之间共享。所以我把这个财产变成了共享财产。在XAML上绑定此属性时,它采用默认值,无法更新。但如果我使用此属性的主要所有者,则可以更新其值 那么你的建议是什么C# 绑定中的共享依赖项属性更新问题,c#,wpf,xaml,dependency-properties,C#,Wpf,Xaml,Dependency Properties,我有一个只读依赖属性,它在两个WPF类之间共享。所以我把这个财产变成了共享财产。在XAML上绑定此属性时,它采用默认值,无法更新。但如果我使用此属性的主要所有者,则可以更新其值 那么你的建议是什么 public class A { private static readonly DependencyPropertyKey XPropertyKey = DependencyProperty.RegisterReadOnly("X", typeof(Poi
public class A
{
private static readonly DependencyPropertyKey XPropertyKey =
DependencyProperty.RegisterReadOnly("X",
typeof(Point), typeof(A),
new FrameworkPropertyMetadata(new Point(0, 0),
FrameworkPropertyMetadataOptions.Inherits |
FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty XProperty =
RelativeMousePointPropertyKey.DependencyProperty;
public Point X
{
get { return (Point)GetValue(XProperty); }
set { SetValue(XProperty, value); }
}
public void SetRelativeMousePoint(Point point)
{
SetValue(XPropertyKey, point);
}
}
public class B
{
//I use this class for binding
public static readonly DependencyProperty XProperty =
A.XProperty.AddOwner(typeof(B));
public Point X
{
get { return (Point)GetValue(X); }
}
}
将物业作为b类业主添加的目的到底是什么?没有钥匙你就无法设置它。记住,仅仅将其添加为所有者并不会在类A和类B之间建立任何类型的关系。类B上的属性X不能做任何事情。你想要实现什么?为什么需要共享?我需要在类B中获取X的值,但X必须是只读属性。Bs X属性没有值,也永远不会有值。您想从中读取什么值?你说的是“B你可以从A获得X属性(不是它的值!!),但不能将其设置为任何值”,再次强调,记住A实例中的属性值与B中的属性值无关。你只是说B也有X属性。