Xamarin.Form.Maps运行到Breakpoint(简单代码)

时间:2016-10-29 08:06:56

标签: c# xamarin.forms

我有一个Xamarin Forms可移植项目。我只是想用Xamarin.Forms.Maps显示一张地图。我创建了一个XAML文件(" MapPageXAML.xaml")。 XML本身如下:

<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
    x:Class="MapDemo.MapPage">
  <StackLayout VerticalOptions="StartAndExpand" Padding="30">
    <maps:Map WidthRequest="320" HeightRequest="200"
        x:Name="MyMap"
        IsShowingUser="true"
        MapType="Hybrid"
        />
  </StackLayout>
</ContentPage>

在MapPageXAML.xaml.cs文件中,我已将Xamarin示例页面中的snippet(在“使用地图&#39;”部分下)插入到构造函数中:

using Xamarin.Forms;
using Xamarin.Forms.Maps;

namespace finderbackend
{
    public partial class MapPageXAML : ContentPage
    {
        public MapPageXAML()
        {
            var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(0.3)))
            {
                IsShowingUser = true,
                HeightRequest = 100,
                WidthRequest = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            var stack = new StackLayout { Spacing = 0 };
            stack.Children.Add(map);
            Content = stack;
        }

    }
}

&#39; MainPage()&#39; Windows 8.1 App的内容如下:

    public MainPage()
    {
        this.InitializeComponent();

        LoadApplication(new finderbackend.App());

        Xamarin.FormsMaps.Init("[my key...]");
    }
}

为了测试,我运行了UWP。调试器现在运行到

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

var e 告诉我以下堆栈跟踪:

   at System.StubHelpers.HStringMarshaler.ConvertToNativeReference(String managed, HSTRING_HEADER* hstringHeader)
   at Bing.Maps.Map.set_Credentials(String newCredentials)
   at Xamarin.Forms.Maps.WinRT.MapRenderer.<OnElementChanged>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

有人可以想象问题是什么吗?我不知道。我确定错误发生在最后一行&#39; Content = stack;&#39;在构造函数中。而且我没有更多的代码......

0 个答案:

没有答案