Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf user control base class problem

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()
    {
        InitializeComponent();
    }

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

error,

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

like image 362
aaron Avatar asked Oct 01 '09 07:10

aaron


2 Answers

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.

like image 58
Paul Stovell Avatar answered Nov 02 '22 03:11

Paul Stovell


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.

like image 1
Danny Varod Avatar answered Nov 02 '22 03:11

Danny Varod