Answered Unable to create abstract parent class

  • Thursday, April 19, 2012 5:34 AM
     
      Has Code

    The following code compiles and runs perfectly in both WPF and Silverlight:

    public abstract class ParentPage:Page
    {
    }
    public sealed partial class BlankPage : ParentPage
    {
        public BlankPage()
        {
            InitializeComponent();
        }
    }

    But in WinRT I get this error which only disappears if you remove the abstract:

    XAML Type 'ParentPage' cannot be constructed. It needs to have a default constructor' 

    I often have abstract parent classes for my controls, because I want to ensure that they cannot be instantiated.  Hope this can be fixed.

    ...Stefan

All Replies

  • Thursday, April 19, 2012 10:36 AM
     
      Has Code

    Hi Stefan,

    like the error message states: You need a default constructor in your abstract class, for example:

    public abstract class ParentPage : Page
    {
        public ParentPage()
        {
            ...
        }
    }

    Best Regards. When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer. This helps us build a healthy and positive community.

  • Thursday, April 19, 2012 10:40 AM
     
      Has Code

    Thanks for the suggestion, unfortunately when the code is like this that gives the same error message:

    public abstract class ParentPage:Page
    {
        public ParentPage()
        {
        }
    }
    public sealed partial class BlankPage : ParentPage
    {
        public BlankPage()
        {
            InitializeComponent();
        }
    }

    XAML Type 'ParentPage' cannot be constructed. It needs to have a default constructor

    Stefan

  • Wednesday, June 06, 2012 2:36 AM
     
     Answered

    This is fixed in RP

    • Marked As Answer by StefanOlson Wednesday, June 06, 2012 2:36 AM
    •