Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've been facing an error that tells me that the partial declarations must not specify a different base class.
C#
public partial class MainWindow : Shape
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Stretch = System.Windows.Media.Stretch.Fill;
            this.StrokeLineJoin = PenLineJoin.Round;
        }

I get error from :
C#
public partial class MainWindow : Shape

The 'MainWindow' gives me error about the specifying of a different base. How do i go about rectifying this error?

My XAML currently, is the default one:
C#
   <Window x:Class="Triangle.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

I have yet to edit anything from the XAML as this codes are codes i found somewhere from online and is using it to try out whether or not it work.
Posted
Comments
Sergey Alexandrovich Kryukov 28-Aug-14 22:55pm    
What can possibly be unclear about this error? What to do? It's up to you. Not a right question. Well, don't violate language rules.
—SA

http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx[^]

Above outlines how to use a derived class instead of the standard Window or Page classes in the XAML. Essentially the XAML element must specify the local base class including its namespace qualifier. e.g.:

XML
<local:Shape x:Class="Triangle.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:<your namespace here>"
  Title="MainWindow" Height="350" Width="525">
  <Grid>
 
  </Grid>
</Shape>
 
Share this answer
 
How, how can you possibly have another base class, Shape?! The window created via XAML has the base class Window; and you are trying to add one more base class. Did you know that in .NET there is no multiple inheritance. Remove everything from inheritance list of the other part (partial declaration) of the class.

Only the weak form of multiple inheritance is allowed, for interfaces. Therefore, in each part, you can add any number of interfaces in inheritance list (of course, you would have to implement all of them).

By the way, the practical consequence from the partial declaration rules is: in all parts, inheritance list should be different (except the empty ones). If a base class or interface is mentioned in one of the parts, no need to mention it in any other parts. And, for maximum maintainability, never repeat them.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900