Skip to content

Common WPF Error – Partial declaration must not specify different base classes

November 4, 2015

Working with WPF applications, you may encounter the following error – Partial declaration must not specify different base classes.

If you get this error, possibly in the situation with migrating from one WPF application to another, you may change the XAML from UserControl to Window class. This is the main reason why this error code and the CS code behind code doesn’t reflect this as you updated the XAML only.
E.g In XAML code of MainWindow.XAML
you have

in CS it is

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SampleProject.Views
{
///

/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : UserControl
{
public MainWindow()
{
InitializeComponent();
}
}
}

Here you may have updated the XAML to be Window, but you have left out in the CS code wherre it as previously UserControl class to now be updated to Window class.

So to correct and remove this error, it should be: –

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SampleProject.Views
{
///

/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

It may also be that you have created a custom class for the Window, and you have not set the namespace class to inherit this, see this link for more details.
http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: