问题
I tried to solve almost same problem: "How to Expose a DependencyProperty of a Control nested in a UserControl?"
The difference is that I have different (2 or more) nested Controls
with of the same type
. My goal is to make the nested DependencyProperties
bindable. The main Problem I am facing is that Binding
don't uses the the Getter
and Setter
of the CLR-Property
but the String
of the registererd DependencyProperty
. With 2 (or more) nested Controls
I am facing a naming conflict.
To illustrate my Problem here the Code of the outer UserControl
:
public partial class OuterControl : UserControl
{
public OuterControl()
{
InitializeComponent();
}
public Visibility PropOfInnerControl
{
get { return (Visibility)GetValue(PropOfInnerControlProperty); }
set { SetValue(PropOfInnerControlProperty, value); }
}
// Using a DependencyProperty as the backing store for UserControl2Visibility. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PropOfInnerControlProperty =
InnerControl.PropOfInnerControlProperty.AddOwner(typeof(OuterControl), new FrameworkPropertyMetadata(MyVisibilityPropertyChanged));
private static void MyVisibilityPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var OuterControl = obj as OuterControl;
OuterControl.InnerControl1.PropOfInnerControl = (Visibility)e.NewValue;
}
}
If it's not clear: In my example the DependencyProperty
of the InnerControl1
is called PropOfInnerControlProperty
and is registerd under the String "PropOfInnerControl"
.
In my example Binding with the InnerControl1
works fine. But I don't know how to resolve the same Problem with the InnerControl2
.
来源:https://stackoverflow.com/questions/21602378/how-to-expose-multiple-dependencyproperties-with-same-name-of-nested-controls