【问题标题】:subclassing PhoneApplicationPage is not calling the inherited methods子类化 PhoneApplicationPage 没有调用继承的方法
【发布时间】:2012-12-10 21:38:43
【问题描述】:

我已经创建了一个这样的基类:

`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));

我只是黑屏,调试输出没有显示任何子类的创建。

你能告诉我我在这里缺少什么吗?

我原以为调用子类与调用基类完全一样。 至少它应该调用Settings_screen_Child()

【问题讨论】:

    标签: c# windows-phone-7 inheritance


    【解决方案1】:

    不知道发生了什么。您应该确保在子页面中引用了正确的基类。我创建了我自己的示例版本,它似乎对我来说工作正常。你可以在这里查看我的示例项目:http://sdrv.ms/XLcyvR

    【讨论】:

    • 我需要的绝对完美 - 非常感谢您的努力!
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2014-05-10
    • 2016-02-09
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    相关资源
    最近更新 更多