I am new to WPF and have created a WPF User Control Library

I added a Base class that looks like this

public class TControl : UserControl

and want all of my controls to inherit from it.

I have a Control called Notification which looks like

public partial class Notification : TControl
    public Notification()

Works fine except when ever i recompile the hidden partial class where InitializeComponent() is defined gets regenerated and inherits from System.Windows.Controls.UserControl

this gives me an

Partial declarations of 'Twac.RealBoss.UserControls.Notification' must not specify different base classes


is there anyway to force the generated class to inherit from my base class?

+3  A: 

Your XAML file probably has:

<UserControl x:Class="YourNamespace.Notification" .... >

Try changing this to:

<Whatever:TControl x:Class="YourNamespace.Notification" xmlns:Whatever="clr-namespace:YourNamespace" />

The error you are getting is because the use of UserControl in the XAML tells the compiler to produce a partial class inheriting from UserControl, instead of inheriting from your class.

Paul Stovell
+1  A: 

You can completely remove the ": TControl":

public partial class Notification : TControl

and write:

public partial class Notification

instead, since the base class is defined in the XAML part, as Paul wrote.

Danny Varod
Absolutely correct, I left it in there however to remind me that it doesn’t just inherit from usercontrol. TControl doesnt do anything yet, but it might in the future
Also, I wouldn't use Hungarian notation (TControl, instead of Control), unlike Delphi it is not recommended in C# (or Java or C++). In Delphi it is only required since the language in not case sensitive.
Danny Varod