XamlParseException when I inherit a Page from a Ge

2019-05-18 11:53发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-05-18 12:35

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

查看更多
登录 后发表回答