子类化PhoneApplicationPage没有调用继承的方法 [英] subclassing PhoneApplicationPage is not calling the inherited methods

查看:69
本文介绍了子类化PhoneApplicationPage没有调用继承的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这样的基类:

`namespace XXX.Screens
{
    public partial class Settings_screen_BASE : PhoneApplicationPage
    {
        public static readonly bool DEBUG = true;

        public Settings_screen_BASE()
        {
            if (DEBUG)
                Debug.WriteLine(this.GetType() + "->" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            InitializeComponent();
            if (DEBUG)
                Debug.WriteLine(this.GetType() + "<-" + System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
    }
}`

这个子类:

 namespace XXX.Screens
{
    public partial class Settings_screen_Child : Settings_screen_BASE
    {

        public Settings_screen_Child()
        {

            if (DEBUG)
                Debug.WriteLine(this.GetType() + "->" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            base.InitializeComponent();
            if (DEBUG)
                Debug.WriteLine(this.GetType() + "<-" + System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
    }
}

我现在打电话给

 this.NavigationService.Navigate(new Uri("/Screens/Settings_screen_BASE.xaml", UriKind.Relative));

效果很好

但是当我打电话

  this.NavigationService.Navigate(new Uri("/Screens/Settings_screen_Child.xaml", UriKind.Relative));

我只得到一个黑屏,调试输出未显示任何子类的创建.

I just get a black screen and the debug output does not show any creation of the child class.

你能告诉我我在这里想念什么吗?

Can you please tell me what I am missing here?

我希望调用子级与调用基类完全一样. 至少它应该调用Settings_screen_Child()

I would have expected that calling the child would do exactly the same as calling the base class. At least it should call Settings_screen_Child()

推荐答案

不确定发生了什么.您应该确保在子页面中引用了正确的基类.我为您的示例创建了自己的版本,对我来说似乎运行良好.您可以在此处查看我的示例项目: http://sdrv.ms/XLcyvR

Not sure what's going on. You should make sure that you are referencing the proper base class in the in the child page. I created my own version of your example, and it seems to be working fine for me. You can check out my sample project here : http://sdrv.ms/XLcyvR

这篇关于子类化PhoneApplicationPage没有调用继承的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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