WPF基本页面问题 [英] WPF Base Page problem

查看:74
本文介绍了WPF基本页面问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试设计WPF页面,该页面将另一个WPF页面作为基本形式.我已经更改了.cs文件中的代码以及XAML标记.
但仍然出现编译错误,提示
"SMS.PgBase不能是XAML文件的根,因为它是使用XAML定义的."

该怎么办?
我的代码有什么问题吗?

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?

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



我的标记.



My mark up.

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





在此先感谢.

克里斯蒂安·格劳斯,您好,
我已经阅读了一些文章,据此我可以继承XAML文件.
在后台为\ obj \ Debug \创建了XAML文件的另一个文件,扩展名为g.cs,其中声明了UI元素.
因此,一个文件会在后台与其他"g.cs"文件联系.
据我所知XAML将支持视觉继承.
如果XAML文件不支持可视继承,则对于XAML和WPF来说将是一个缺点.
是不是?





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?

推荐答案

不幸的是,在尝试删除您的假答案时,在编辑您的帖子以将其答案放在应有的位置后,我不小心删除了我的答案.但是,我注意到您为帮助您而给了我1票,所以我不确定我还要说什么.


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写道:
cv_sudheer wrote:

因此,一个文件与后台的其他"g.cs"文件联系起来.

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写道:
cv_sudheer wrote:

据我所知XAML将支持视觉继承.

as of my knowledge that XAML will support visual inheritance.



好吧,您的理解似乎是错误的.



Well, your understanding appears to be wrong.

cv_sudheer写道:
cv_sudheer wrote:

SMS.PgBase不能是XAML文件的根,因为它是使用XAML定义的."

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



错误是告诉您您做不到.您还有什么其他问题?我在Google上搜索了一下,也许这在某个阶段得到了支持,但是每个人都同意现在明确禁止这样做.这是有道理的.正如我在回复中所说,您是否投票赞成,如果page1中存在XAML,而page2中存在XAML,它是从page1派生的,那么page1 XAML会在page2内部呈现在哪里?您需要像ASP.NET中的母版页"这样的显式机制,以便在逻辑上定义类似的内容.没有这样一个明确的定义,它将无法正常工作.

实际上,我在google上找到的线程是您在MSDN上询问完全相同的内容的地方.但是,将其缩短为EXACT错误消息,而不是您发布的消息,却给我带来了很多点击,包括 [ ^ ].我建议以后,在这种情况下,您的第一个调用端口应该是在引号中输入EXACT错误消息(用引号引起来),不要将任何具有您特定类名称的位输入到google中,然后看看您得到了什么.我是对的.不支持.您无法做到.



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.


您的xaml不正确.

您需要执行以下操作:

Your xaml isn''t correct.

You need to do something like this:

<baseClassNameSpace:PgBase x:Class="SMS.PgMngMarks"
    xmlns:baseClassNameSpace="clr-namespace:project.namespace">


上一个答案通常是正确的. XAML中的继承是通过代码包含,而C#中的继承是通过类继承.您可以通过在公共XAML代码文件中声明包含该文件的方式来包含该文件.当前的信念是,所有基类都应使用C#代码进行完整详细说明.

如果您想尝试进行实验以查看它是否完全可以工作,请在您的基类代码中包含一个XAML文件,并为其命名(PgBase是您建议的名称).您没有在示例中表明您的基类XAML代码实际上具有名称.

最重要的是,您没有给出打算这样做的任何理由.这使答案不稳定,因为您缺乏足够的解释来让其他人适当地帮助您.因此,我和其他相信您正在尝试捷径的人在一起,应该将基类完全放在C#代码中.您未来的成功很大程度上取决于您是否充分了解实现特定效果的可用方法.
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.


这篇关于WPF基本页面问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆