本文介绍了当我从通用基类继承 Page 时出现 XamlParseException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用这个确切的代码:

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();
    }
}

还有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>

当我尝试构建此页面时,出现错误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 未被用户代码处理
HResult=-2144665590 Message=BaseMainMenuView 不支持网格作为内容.[行:12 位置:22] Source="" StackTrace:在 Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation组件资源位置)在 c:\Projects\Misc\MvvmCross\Sample 中的 Tutorial.UI.WinRT.Views.MainMenuView.InitializeComponent() -Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\Views\MainMenuView.g.i.cs:line34在 c:\Projects\Misc\MvvmCross\Sample 中的 Tutorial.UI.WinRT.Views.MainMenuView..ctor() -Tutorial\Tutorial\Tutorial.UI.WinRT\Views\MainMenuView.xaml.cs:line 40在 Tutorial.UI.WinRT.XamlTypeInfo.XamlTypeInfoProvider.Activate_3_MainMenuView()在 c:\Projects\Misc\MvvmCross\Sample -Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\XamlTypeInfo.g.cs:line122在 Tutorial.UI.WinRT.XamlTypeInfo.XamlUserType.ActivateInstance() 中c:\Projects\Misc\MvvmCross\Sample -Tutorial\Tutorial\Tutorial.UI.WinRT\obj\x86\Debug\XamlTypeInfo.g.cs:line314 内部异常:

如果我尝试将代码简化为:

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();
    }
}

然后页面加载正常.

我完全不理解异常 - 我为它找到的所有必应/谷歌点击,建议 Silverlight 2 问题.

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?

推荐答案

Stuart 请在 Release Preview 上试试这个,因为我相信这个问题会得到解决

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

这篇关于当我从通用基类继承 Page 时出现 XamlParseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 05:03