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

    技术2025-02-19  11

    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"  wpf wpf-controls link | edit | flag asked Jan 26 at 17:48 user310291 2,116 1 10 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 answered Jan 26 at 21:20 TimothyP 2,766 3 20 35 Hi thanks that was indeed linked to inheritance. I've solved the problem. –  user310291 Jan 28 at 0:32
    最新回复(0)