XamlParseException when I inherit a Page from a Generic base class

Deadly 提交于 2019-12-07 20:43:08

问题


I'm currently working with this exact code:

public class ViewModelAwarePage<T> : Page
{        
}

public class BaseMainMenuView 
    : ViewModelAwarePage<String>
{     
}

public sealed partial class MainMenuView
    : BaseMainMenuView
{
    public MainMenuView()
    {
        this.InitializeComponent();
    }
}

And xaml:

<local:BaseMainMenuView
x:Name="pageRoot"
x:Class="Tutorial.UI.WinRT.Views.MainMenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Tutorial.UI.WinRT.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundBrush}">

</Grid>

</local:BaseMainMenuView>

When I try to construct this page then I get the error "BaseMainMenuView does not support Grid as content"

Windows.UI.Xaml.Markup.XamlParseException was unhandled by user code
HResult=-2144665590 Message=BaseMainMenuView does not support Grid as content. [Line: 12 Position: 22] Source="" StackTrace: at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation) at Tutorial.UI.WinRT.Views.MainMenuView.InitializeComponent() in c:\Projects\Misc\MvvmCross\Sample - Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\Views\MainMenuView.g.i.cs:line 34 at Tutorial.UI.WinRT.Views.MainMenuView..ctor() in c:\Projects\Misc\MvvmCross\Sample - Tutorial\Tutorial\Tutorial.UI.WinRT\Views\MainMenuView.xaml.cs:line 40 at Tutorial.UI.WinRT.XamlTypeInfo.XamlTypeInfoProvider.Activate_3_MainMenuView() in c:\Projects\Misc\MvvmCross\Sample - Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\XamlTypeInfo.g.cs:line 122 at Tutorial.UI.WinRT.XamlTypeInfo.XamlUserType.ActivateInstance() in c:\Projects\Misc\MvvmCross\Sample - Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\XamlTypeInfo.g.cs:line 314 InnerException:

If I try reducing the code to:

public class ViewModelAwarePage : Page
{        
}

public class BaseMainMenuView 
    : ViewModelAwarePage
{     
}

public sealed partial class MainMenuView
    : BaseMainMenuView
{
    public MainMenuView()
    {
        this.InitializeComponent();
    }
}

then the page loads fine.

I don't understand the exception at all - all the Bing/Google hits I find for it, suggest Silverlight 2 problems.

Can anyone explain the error - can anyone suggest ideas for how I might be able to inherit from a generic page?


回答1:


Stuart please try this on the Release Preview as I believe this to be fixed



来源:https://stackoverflow.com/questions/9699215/xamlparseexception-when-i-inherit-a-page-from-a-generic-base-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!