title: Limit attached dependency property in wpf
body: <p>I want to attach a dependency property to specific controls only.  </p>
  
  <p>If that is just one type, I can do this:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p><em>(So: limit the <code>Control</code> type in the Get/Set-Methods)</em></p>
  
  <p>But now I want to allow that property to get attached on a different type of <code>Control</code>, too.<br>
  You'd try to add an overload for both methods with that new type, but that fails to compile because of an <em>"Unknown build error, Ambiguous match found."</em></p>
  
  <p>So how can I limit my <code>DependencyProperty</code> to a selection of <code>Control</code>s?<br>
  <em>(Note: In my specific case I need it for <code>TextBox</code> and <code>ComboBox</code>)</em></p>