![](/img/trans.png)
[英]subclassing PhoneApplicationPage is not calling the inherited methods
[英]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.