subclassing PhoneApplicationPage is not calling th

2019-09-10 18:56发布

问题:

I have created a Base class like this:

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

And this child class:

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

When I now call:

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

It works well,

but when I call

  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?

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

回答1:

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