简体   繁体   中英

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. 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.

It's the Cannot create an instance of WindowsPage error message in the Microsoft Visual Studio 2015 Xaml designer. 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.

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. 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.

Here's the XAML code

<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".

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.". 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. The ContentPage is Xamarin Forms version of WPF's Page. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM