WPF error message: Partial declaration must not specify different base classes

来源:互联网 发布:编程单引号怎么打出来 编辑:程序博客网 时间:2024/05/22 06:46

WPF error message: Partial declaration must not specify different base classes

up vote 0 down vote favorite

Why do I have this error message for a UserControl:

Partial declaration of MyNamespace.MyUserControl must not specify different base classes

Just because I inherited from another UserControl class I created in another namespace whereas this other namespace is referenced in the XAML as

xmlns:my="clr-namespace:ReferedNamespace;assembly=ReferedNamespace" 
link|edit|flag

70% accept rate
 
1  
can you post more xaml and declaration of your calls – baalazamon Jan 26 at 18:20

1 Answer

active oldest votes
up vote 1 down vote accepted

Hi, Little to go on here, but this usually happens when the code behind and the xaml file do not inherit from the same base class.

Since we do not have all the details concerning your problem, I'll create a situation that will cause the same exception to be thrown, this might help you understand your problem.

As an example, just create new WPF application using Visual Studio, The XAML might look something like this:

<Window x:Class="WpfApplication1.MainWindow" .....> 

The code behind would then contain something like this:

public partial class MainWindow : Window 
{ 
   
//Code here 
} 

Note the 'partial' modifier here. It means this class (MainWindow) might not be defined in a single file but spread out across multiple files, in this case the XAML (.xaml.cs) and the CS (.cs) files.

Now add a new UserControl to the solution. It will be named UserControl1.

Without making any changes to the XAML, change the code behind for the MainWindow:

public partial class MainWindow : UserControl1 
{ 
   
//Code here 
} 

Now you'll get the exception you questioned about.

Look for something like this in your code, if you still can't find a solution, please provide more code.

link|edit|flag
Hi thanks that was indeed linked to inheritance. I've solved the problem. – user310291 Jan 28 at 0:32
原创粉丝点击