Exception 在Xamarin表单选项卡页面中使用SkiaSharep API时出现异常

Exception 在Xamarin表单选项卡页面中使用SkiaSharep API时出现异常,exception,xamarin.forms,skiasharp,tabbedpage,Exception,Xamarin.forms,Skiasharp,Tabbedpage,在Xamarin表单的选项卡式页面的子页面中使用SkiaSharep API绘制一个圆圈时,我遇到了一些问题 尽管我在构建项目期间没有收到任何错误,但每当我进入在设备调试期间应该绘制圆圈的页面时,应用程序就会抛出“System.InvalidCastException:Specified cast is not valid”消息,并崩溃 这是选项卡式页面的XAML代码: <?xml version="1.0" encoding="utf-8" ?> <TabbedPage x

在Xamarin表单的选项卡式页面的子页面中使用SkiaSharep API绘制一个圆圈时,我遇到了一些问题

尽管我在构建项目期间没有收到任何错误,但每当我进入在设备调试期间应该绘制圆圈的页面时,应用程序就会抛出“System.InvalidCastException:Specified cast is not valid”消息,并崩溃

这是选项卡式页面的XAML代码:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage  xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:me="clr-namespace:TestBth;assembly=TestBth"
             x:Class="TestBth.MyTabbedPage">

    <TabbedPage.Children>

        <me:ConnectPage />
        <me:LissajousPage />
        <me:ParametersPage />

    </TabbedPage.Children>

    <!--Pages can be added as references or inline-->


</TabbedPage>
你知道为什么会这样吗


提前谢谢。

让我惊讶的是,原来SkiaSharep.Views.Forms Nuget软件包不是为Android安装的

我指定要在所有项目中安装它,但安装过程中一定出现了问题

我为Android单独安装了这个软件包,现在可以正常工作了


很抱歉给您带来不便。

应该可以,您可以发布输出完整异常详细信息吗?您是否费心检查堆栈跟踪?结果表明,Android没有安装SkiaSharep.Views.Forms Nuget软件包。我指定要在所有项目中安装它,但安装过程中一定出现了问题。我为Android单独安装了这个软件包,现在可以正常工作了。很抱歉给您带来不便。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
             xmlns:local="clr-namespace:TestBth"
             x:Class="TestBth.LissajousPage"
             Title="Lissajous">

            <skia:SKCanvasView x:Name="canvasView"
                               PaintSurface="canvasView_PaintSurface" />

</ContentPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

using SkiaSharp;
using SkiaSharp.Views.Forms;

namespace TestBth
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class LissajousPage : ContentPage
    {

        SKPaint blackFillPaint = new SKPaint
        {
            Style = SKPaintStyle.Fill,
            Color = SKColors.Black
        };

        public LissajousPage()
        {
            InitializeComponent();
        }


        private void canvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface = e.Surface;
            SKCanvas canvas = surface.Canvas;

            canvas.Clear(SKColors.CornflowerBlue);

            int width = e.Info.Width;
            int height = e.Info.Height;

            //Set transforms
            canvas.Translate(width / 2, height / 2);
            canvas.Scale(width / 200f);

            //Clock Background
            canvas.DrawCircle(0, 0, 100, blackFillPaint);
        }

    }
}