扩展页面类 [英] Extend Page class

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

问题描述

是否可以在C#的WPF工具包中扩展页面"类(或分别扩展到其他任何WPF类)? 我想做的事:

Is it possible to extend the "Page"-class in C#'s WPF-toolkit (or, respectively, any other WPF-class)? What i tried to do:

public class ExtendedPage : Page{
   protected void doStuff(){
      // lots of joy n pleasure
   }
}

public partial class RandomWindow : ExtendedPage{
   private void randomMethod(){
      doStuff(); // causes error
   }
}

我要问的原因很明显:扩展Page类(ExtendedPage)后,子类(RandomWindow)无法访问其基类的方法. 这(至少是我的猜测)是由RandomWindow部分出现的情况引起的.由于不幸的是,该类是由WPF生成的(链接到相应的* .xaml),因此无法找到部分类的另一部分.

The reason I'm asking is pretty obvious: After extending the Page-class (ExtendedPage), the subclass (RandomWindow) has no acces to the methods of its base. This (at least it's my guess) caused by the circumstance of RandomWindow being partial. Since this class unfortunately is generated by WPF (links to the corresponding *.xaml), I'm unable to locate the other part of the partial-class.

这个问题可能会导致一个很明显的答案,使我看起来像个笨蛋,但显然我无法弄清楚.我可能会补充说,我刚开始使用C#,我的编程起源是Java.

This question might lead to a pretty obvious answer that makes me look like a total moron, but apprently I'm unable to figure it out. I might add that I've just started working with C#, my programming origin is Java.

确切的错误消息是类型的部分声明不能指定不同的基类"(CS0263).

The exact error-message is "Partial declarations of 'type' must not specify different base classes" (CS0263).

作为对其中一项评论的回应:* .xaml中的"Page"声明似乎生成了一个代码隐藏文件,其基类为"Page"(而不是ExtendedPage).更改它似乎也不起作用,编译器会抱怨找不到ExtendedPage类型.

As response to one of the comments: The declaration of "Page" in the *.xaml seems to generate an code-behind-file whose base-class is "Page" (and not ExtendedPage). Changing this seems not to work either, the compiler complains about the type ExtendedPage not being found.

<Page x:Class="...RandomWindow" ... />
// to
<src:ExtendedPage x:class="...RandomWindow" 
xlmns:src="...ExtendedPage" />

推荐答案

类型"的部分声明不能指定不同的基类

Partial declarations of 'type' must not specify different base classes

嗯,这很容易理解,您可能在某个地方有一个XAML,看起来像这样:

Well, that one's a no-brainer, you probably have a XAML somewhere which looks like this:

<Page x:Class="MyApp.MyNamespace.RandomWindow" ....>

隐式地指定Page作为基础,但是您需要:

Implicitly specifying a Page as the base, you need however:

<local:ExtendedPage x:Class="MyApp.MyNamespace.RandomWindow"
                    xmlns:local="clr-namespace:MyApp.NSContainingExtendedPage"
                    ...>

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

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