According to all of the documentation, when you're creating a non-lookless control, you're supposed to subclass UserControl
. However, UserControl
is a simple subclass of ContentControl
but it doesn't appear to add anything to it, interface-wise. As such, you can take that designer-generated code and change the base class to ContentControl
and it appears to still work exactly the same.
So what's the point of UserControl
over ContentControl
?
Update:
For those who keep answering Visual Studio treats them differently, I'd argue that isn't the case. Try it! Create a new UserControl
in Visual Studio, then in the resulting XAML file, change the root tag to ContentControl
. Then in the associated class file, change the base class to ContentControl
or simply delete it as I have done here (see the note) and you'll see it appears to work exactly the same, including full WYSIWYG designer support.
Note: You can delete the base class from the code-behind because it's actually a partial class with the other 'part' of the class being created by the XAML designer via code-generation. As such, the base class will always be defined as the root element of the XAML file, so you can simply omit it in the code-behind as it's redundant.
Here's the updated XAML...
<ContentControl x:Class="Playground.ComboTest.InlineTextEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="Success" />
</ContentControl>
...and the associated class file...
namespace Playground.ComboTest {
public partial class InlineTextEditor {
public InlineTextEditor()
=> InitializeComponent();
}
}
ContentControl
is thatUserControl
overrides theOnCreateAutomationPeer
method, you might look for that. Maybe it has some different UI-behaviors than the ContentControl. – Drumhead