简体   繁体   中英

Error in PhoneApplicationPage subclassing thrown only by XAML designer

In my Windows Phone 7.1 application, I have some pages made in this way:

<views:EntityListPage x:Class="Ribo.Smart.X.CustomersPage"
                      x:Name="MainWindow"
                      xmlns:views="clr-namespace:Ribo.Smart.X.Views"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                      xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                      xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
                      xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                      mc:Ignorable="d"
                      d:DesignWidth="480"
                      d:DesignHeight="768" 
                      FontFamily="{StaticResource PhoneFontFamilyNormal}"
                      FontSize="{StaticResource PhoneFontSizeNormal}"
                      Foreground="{StaticResource PhoneForegroundBrush}"
                      Loaded="MainWindow_Loaded"
                      SupportedOrientations="Portrait"
                      Orientation="Portrait"
                      shell:SystemTray.IsVisible="True">
    <views:EntityListPage.Resources>
         ....
    </views:EntityListPage.Resources>

    ...
</views:EntityListPage>

This is more or less the code-behind of my view:

public partial class CustomersPage : EntityListPage
{
    public CustomersPage()
    {
        InitializeComponent();
    }

    ... other stuff here ...
    ... of course I'm overriding all the methods of the base abstract class ...
    ... (see the ancestor definition) ...
}

Where my EntityListPage class is defined in the next way:

public abstract class EntityListPage : PhoneApplicationPage
{
    ... a lot of stuff here! ...
}

If I run this code, all works well and there also no compilation/building errors, of any type!

But if I open the XAML designer of my CustomersPage view, it cannot load the layout of my page, and it will show up the next error (but it will not interfere with the project!):

Cannot create an instance of "EntityListPage".  

I cannot figure out why the designer can't show me the layout and gives error, while at runtime all works fine and I have no problems/exceptions at all!

Thank you!

Very easy: the problem is just on your EntityListPage , that is abstract.

If you remove the abstract clause to your ancestor class, and transform all your methods to virtual ones (and not abstract methods, otherwise you'll need to set the whole class as abstract ), you should have no problems with the designer.

It's a strange error, but it can be managed...

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM