Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
like image 730
user310291 Avatar asked Jan 26 '11 17:01

user310291


2 Answers

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.

like image 134
TimothyP Avatar answered Oct 20 '22 17:10

TimothyP


look to both your .cs and .xaml files at this parts

  • in .xaml file :

    <Window x:Class="BUSsAsDesign.GUI.IGPopUP" > ...... </Window>
    
  • in .cs file :

    namespace BUSsAsDesign.GUI
    {
       public partial class IGPopUP : Window
      {
    
       //code here
    
      }
    }
    
  • Now if u wanna change Window to UserControl

  • change

    <Window x:Class="BUSsAsDesign.GUI.IGPopUP" > ....... </Window>
    <!--**becomes**-->
    <UserControl x:Class="BUSsAsDesign.GUI.IGPopUP" > ....... </UserControl>
    

    namespace BUSsAsDesign.GUI
    {
      public partial class IGPopUP : Window
      {

       //code here

      }
    }
    //**becomes**
    namespace BUSsAsDesign.GUI
    {
      public partial class IGPopUP : UserControl
      {

       //code here

       } 
    }

- i hope it`s useful :) .

like image 41
Sherif Mo Shalaby Avatar answered Oct 20 '22 18:10

Sherif Mo Shalaby