Wpf 依赖属性-如何添加所有者,使其充当附加属性?
基本上,是否有任何方法将所有者添加到DependencyProperty,使其成为新所有者的附加属性?这样我可以做一些事情,比如: PrimaryControl-原始所有者Wpf 依赖属性-如何添加所有者,使其充当附加属性?,wpf,dependency-properties,attached-properties,Wpf,Dependency Properties,Attached Properties,基本上,是否有任何方法将所有者添加到DependencyProperty,使其成为新所有者的附加属性?这样我可以做一些事情,比如: PrimaryControl-原始所有者 其他控制-第二所有者 <my:Something my:OtherControl.MyProperty="hello world" /> 是的,您可以使用。您的另一个控件如下所示: public static class OtherControl { // MyProperty attached pr
其他控制-第二所有者
<my:Something my:OtherControl.MyProperty="hello world" />
是的,您可以使用。您的另一个控件如下所示:
public static class OtherControl {
// MyProperty attached property
public static readonly DependencyProperty MyPropertyProperty =
PrimaryControl.MyPropertyProperty.AddOwner(typeof(OtherControl));
public static string GetMyProperty(DependencyObject obj) {
return (string)obj.GetValue(MyPropertyProperty);
}
public static void SetMyProperty(DependencyObject obj, string value) {
obj.SetValue(MyPropertyProperty, value);
}
}
你想通过这样做实现什么?这似乎是在控件之间创建依赖关系的一种非常混乱的方式。。。