简体   繁体   English

仅XAML设计器抛出PhoneApplicationPage子类化错误

[英]Error in PhoneApplicationPage subclassing thrown only by XAML designer

In my Windows Phone 7.1 application, I have some pages made in this way: 在我的Windows Phone 7.1应用程序中,我以这种方式制作了一些页面:

<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: 用以下方式定义我的EntityListPage类的位置:

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!): 但是,如果我打开客户页面视图的XAML设计器,它将无法加载页面的布局,并且将显示下一个错误(但不会干扰项目!):

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. 很简单:问题就在您的EntityListPage ,那是抽象的。

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. 如果将祖先类的abstract子句删除,并将所有方法转换为virtual方法(而不是abstract方法,否则将整个类设置为abstract ),那么设计器应该没有问题。

It's a strange error, but it can be managed... 这是一个奇怪的错误,但是可以解决...

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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