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" 
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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值