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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With