繁体   English   中英

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

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

在我的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>

这或多或少是我观点的代码背后:

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

用以下方式定义我的EntityListPage类的位置:

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

如果我运行此代码,则一切正常,也不会出现任何类型的编译/构建错误!

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

Cannot create an instance of "EntityListPage".  

我无法弄清楚为什么设计师不能向我展示布局并给出错误,而在运行时一切正常,而且我没有任何问题/异常!

谢谢!

很简单:问题就在您的EntityListPage ,那是抽象的。

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

这是一个奇怪的错误,但是可以解决...

希望这可以帮助!

暂无
暂无

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

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