Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
4.89/5 (2 votes)
See more:
Hi,
I am trying to a design WPF page which takes another WPF page as base form. I had changed the code in .cs file as well as XAML mark up.
but still getting a compilation error saying that
"SMS.PgBase cannot be root of a XAML file because it was defined using XAML."

what to do?
Is any thing wrong in my code?

MIDL
namespace SMS
{
    /// <summary>
    /// Interaction logic for PgMngMarks.xaml
    /// </summary>
    public partial class PgMngMarks : PgBase
    {
        public PgMngMarks()
        {
            InitializeComponent();
        }
    }
}


My mark up.

XML
<my:PgBase x:Class="SMS.PgMngMarks"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:SMS"
    Title="PgMngMarks">
    <Grid>
        
    </Grid>
</my:PgBase>




Thanks in Advance.

Hi Christian Graus,
I have read some articles and according to that I can inherit XAML files.
In back ground another file is created for XAML file at \obj\Debug\ with g.cs extension, in which the the UI elements are declared.
So one file contacts with other 'g.cs' file in background.
as of my knowledge that XAML will support visual inheritance.
If visual inheritance is not supported for XAML file,it will be a drawback for XAML and WPF.
isn't it?
Posted
Updated 11-Feb-10 23:21pm
v3

Unfortunately, while trying to delete your fake answer, after editing your post to put your response where it belongs, I accidentally deleted my answer. However, I notice you gave me a 1 vote for trying to help you, so I'm not sure what else I should say.


cv_sudheer wrote:
So one file contacts with other 'g.cs' file in background.


Correct, that's a machine generated file. It has nothing to do with your question.

cv_sudheer wrote:
as of my knowledge that XAML will support visual inheritance.


Well, your understanding appears to be wrong.

cv_sudheer wrote:
SMS.PgBase cannot be root of a XAML file because it was defined using XAML."


The error is TELLING you that you can't do it. What other questions did you have ? I googled and it seems this was supported at one stage, perhaps, but everyone agrees that it's explicitly forbidden now. Which makes sense. As I said in the reply you downvoted, if there's XAML in page1, and there's XAML in page2, which derives from page1, where does the page1 XAML get rendered inside page2 ? You'd need an explicity mechanism like Master Pages in ASP.NET in order to define something like that logically. Without such an explicit definition, it just can't work.

Actually, the thread I found with google is where you asked the exact same thing on MSDN. However, shortening it to the EXACT error message, and not what you posted, gave me a ton of hits, including this[^]. I suggest in future, your first port of call in a situation like this should be to type the EXACT error message, in quotes, without any bits that have the name of your specific classes, into google, and see what you get. I was right. It's not supported. You can't do it.
 
Share this answer
 
Your xaml isn't correct.

You need to do something like this:

<baseClassNameSpace:PgBase x:Class="SMS.PgMngMarks"
    xmlns:baseClassNameSpace="clr-namespace:project.namespace">
 
Share this answer
 
v2
The previous answer is generally correct. Inheritance in XAML is by code inclusion, and in C# by class inheritance. You can include the file by making a statement including it in the common XAML code file. The current belief is that all base classes should be completely detailed in C# code.

If you want to try an experiment to see if this will work at all, include a XAML file of your base class code and give it a name( PgBase is the one you are suggesting). You didn't show that your base class XAML code actually has a name in the example.

Most importantly, you didn't give any reason why you intended to do this. That makes answers erratic because you lacked a sufficient explanation to let others help you properly. So, I'm with the others that believe that you are trying to take a shortcut and you should put the base class entirely in C# code. Your future success depends largely on the degree that you fully understand the available ways to achieve a specific effect.
 
Share this answer
 
 
Share this answer
 
Comments
Tim Corey 28-Jun-12 10:08am    
This question was already answered over two years ago. You are also not adding anything substantive to the question here. Please do not spam answers like this.

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