I want to attach a dependency property to specific controls only.
If that is just one type, I can do this:
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.RegisterAttached("MyProperty", typeof(object), typeof(ThisStaticWrapperClass));
public static object GetMyProperty(MyControl control)
{
if (control == null) { throw new ArgumentNullException("control"); }
return control.GetValue(MyPropertyProperty);
}
public static void SetMyProperty(MyControl control, object value)
{
if (control == null) { throw new ArgumentNullException("control"); }
control.SetValue(MyPropertyProperty, value);
}
(So: limit the Control type in the Get/Set-Methods)
But now I want to allow that property to get attached on a different type of Control, too.
You'd try to add an overload for both methods with that new type, but that fails to compile because of an "Unknown build error, Ambiguous match found."
So how can I limit my DependencyProperty to a selection of Controls?
(Note: In my specific case I need it for TextBox and ComboBox)