简体   繁体   English

如何解决异常:无法创建“WindowsPage”的实例

[英]How to Resolve Exception: Cannot create an instance of “WindowsPage”

Brand new to Xamarin forms here and trying to get started in cross platform app development using the package. 这里是Xamarin的全新形式,并尝试使用该软件包开始跨平台应用程序开发。 However right out of the gate I seem to be running into an issue that has been asked a few times elsewhere but I haven't really seen an actual response on. 然而,在门外我似乎遇到了一个问题,在其他地方被问过几次,但我还没有真正看到实际的回应。 Currently I'm trying to work on the UWP / Universal Windows / Windows 10 User Interface in a Portable Forms / PCL setup. 目前我正在尝试在便携式表格/ PCL设置中使用UWP /通用Windows / Windows 10用户界面。

It's the Cannot create an instance of WindowsPage error message in the Microsoft Visual Studio 2015 Xaml designer. 这是无法在Microsoft Visual Studio 2015 Xaml设计器中创建WindowsPage错误消息的实例。 I'm following the guide at https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/ so I added the line for "xmlns:forms="using:Xamarin.Forms.Platform.UWP" the xaml file before changing the page tag from Page to forms:WindowsPage thus referencing the xamarin forms package. I did update all the NuGet packages to the latest version. Xamarin forms is something like 2.2 at the moment. 我正在按照https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/上的指南进行操作,因此我添加了“xmlns:forms =”的行:Xamarin.Forms .Platform.UWP“将页面标记从页面更改为表单之前的xaml文件:WindowsPage因此引用了xamarin表单包。我确实将所有NuGet包更新到最新版本。目前Xamarin表单类似于2.2。

I initially installed the defaults for the VS2015 Xamarin package and I just tried modifying that installation with every extra component included so I don't think I'm missing anything there. 我最初安装了VS2015 Xamarin软件包的默认设置,我只是尝试使用包含的每个额外组件来修改该安装,所以我不认为我错过任何东西。 I believe Xamarin is installed properly since it shows up in the Help -> Xamarin menu and I can choose new solutions out of the Xamarin forms package but I'm not sure what could be causing the issue. 我相信Xamarin安装正确,因为它显示在帮助 - > Xamarin菜单中,我可以从Xamarin表单包中选择新的解决方案,但我不确定是什么原因导致了这个问题。

Here's the XAML code 这是XAML代码

<forms:WindowsPage
    x:Class="SoloPathfinderPCL.UWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:forms="using:Xamarin.Forms.Platform.UWP"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SoloPathfinderPCL.UWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

</forms:WindowsPage>

Here's my Stack Trace for Exception: Cannot create an instance of "WindowsPage". 这是我的异常堆栈跟踪:无法创建“WindowsPage”的实例。

at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Type type, Boolean supportInternal)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.UserControlInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ViewNodeManager.CreateInstance(IInstanceBuilder builder, ViewNode viewNode)

Hope someone can point me and everyone else having this issue in the right direction. 希望有人可以指出我和其他人在正确的方向上解决这个问题。 Thanks. 谢谢。

It looks like this problem is from Xamarin Forms, According to Xamarin Forms as of right now there is no support for the Visual Studio Form Designer, if you goto the website it states "Note: Xamarin.Forms is not compatible with pre-existing XAML visual designers.". 看起来这个问题来自Xamarin Forms,根据Xamarin Forms,目前还没有对Visual Studio表单设计器的支持,如果你转到网站它说“注意:Xamarin.Forms与预先存在的XAML不兼容视觉设计师。“ Unfortunately you CAN NOT simply change: 不幸的是,你不能简单地改变:

public partial class MainPage : ContentPage

to

public partial class MainPage : Page

this will defeat the whole purpose. 这将打败整个目的。 What you are essentially doing is deriving from the WPF not Xamarin Forms. 你基本上做的是从WPF派生而不是Xamarin Forms。 The ContentPage is Xamarin Forms version of WPF's Page. ContentPage是WPF页面的Xamarin Forms版本。 Another thing to note is even if you were able to get the Designer to load you do not want to use any of the Controls in the "Toolbox", those are again only for WPF. 另外需要注意的是,即使您能够让Designer加载您不想使用“工具箱”中的任何控件,这些也仅适用于WPF。 If you were to use any of the .Net Controls, it would run under Windows but if you were to try and run it under a different platform it would crash because Xamarin Forms eventually maps the Controls to the Native OS's control and the ones in the Toolbox are only for the Windows OS. 如果您使用任何.Net控件,它将在Windows下运行但如果您尝试在不同的平台下运行它会崩溃,因为Xamarin Forms最终将控件映射到Native OS的控件和工具箱仅适用于Windows操作系统。

暂无
暂无

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

相关问题 如何异常解决:“如果对象已由另一个领域管理,则无法开始管理该领域的对象” - How to resolve with a exception “Cannot start to manage an object with a realm when it's already managed by another realm” 如何在 Xamarin Forms 中创建一个 Httpclient 实例 - How to create one instance of Httpclient in Xamarin Forms 如何在没有Android活动的情况下创建Worklight实例 - How to create Worklight instance without Android Activity 无法在MvxFramentActivity中解析SupportFragmentManager - Cannot resolve SupportFragmentManager in MvxFramentActivity 如何解决“无法初始化uikit.uiimage类型的实例:图标选项卡式页面中的本机initwithcontentsofFile”错误 - How to resolve 'could not initialize an instance of the type uikit.uiimage : The native initwith contentsofFile' errors in icons tabbed page Xamarin-无法创建android Black应用:“对象引用未设置为对象的实例” - Xamarin - Cannot create android Black app : “Object reference not set to an instance of an object” 无法创建 Android.Widget.ArrayAdapter`1[T] 的实例,因为 Type.ContainsGenericParameters 为 true - Cannot create an instance of Android.Widget.ArrayAdapter`1[T] because Type.ContainsGenericParameters is true System.MemberAccessException:无法创建UserNotifications.UNNotificationTrigger的实例,因为它是一个抽象类 - System.MemberAccessException: Cannot create an instance of UserNotifications.UNNotificationTrigger because it is an abstract class Autofac 使用不同的参数解析相同的 class 实例 - Autofac resolve the same class instance with different parameters 系统异常:&#39;无法创建没有列的表,它具有公共属性吗? - System Exception: 'Cannot create a table without columns, does it have public properties?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM