3

I am using WPF, and I have written a CustomControl which inherits from a System.Windows.Controls.UserControl, but when I create a new instance of it (CustomControl), and try to add it as a children to a StackPanel, the debugger says that it cannot convert CustomControl to UIElement.

I would guess that UserControl inherits from UIElement itself, so what's going on?

Thanks!

  • 3
    Please post your code. – Connell.O'Donnell Apr 05 '17 at 15:55
  • 1
    The WPF `UserControl` type does inherit `UIElement`. So, your object clearly does not inherit the WPF `UserControl`. Whether that's because you aren't inheriting any `UserControl` type, or because you're inheriting the wrong `UserControl` type (e.g. `System.Windows.Forms.UserControl` instead of `System.Windows.Controls.UserControl`), is impossible to say because you haven't shared a good [mcve] that reliably reproduces the problem. Please improve your question. – Peter Duniho Apr 05 '17 at 17:24

0 Answers0