Sergey Borodin
Sergey Borodin

Reputation: 41

How to use SkiaSharp.Views.UWP?

Is any one know how to use SKXamlCanvas in SkiaSharp.Views.UWP namespace?

I found information just about SkiaSharp.Views.Forms and SKCanvasView.

In official website we have https://developer.xamarin.com/api/namespace/SkiaSharp.Views.UWP/

But nuget did not know anything about UWP. Nuget have packages only for Forms.

Upvotes: 2

Views: 2434

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39102

Check out the UWP sample in the SkiaSharp repository on GitHub.

They are using the Canvas like this:

<Page
    x:Class="SkiaSharpSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SkiaSharpSample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:skia="using:SkiaSharp.Views.UWP"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <skia:SKXamlCanvas PaintSurface="OnPaintSurface" />
    </Grid>
</Page>

The important thing here is to import the SkiaSharp.Views.UWP namespace using xmlns attribute so that you can use it in XAML.

The namespace itself should be available after you install the SkiaSharp.Views NuGet package into your UWP project. Please note, that you can access the SKXamlCanvas only from the UWP project, not from a shared class library.

In case you use SkiaSharp.Forms, things are a bit different. You don't use SKXamlCanvas directly. Instead the library uses SkiaSharp.Views.Forms.SKCanvasView in the shared library and then uses Xamarin.Forms custom renderer to render this view as SKXamlCanvas on UWP (see the source code here). Basically you shouldn't have to use SKXamlCanvas directly and use SKCanvasView instead.

Upvotes: 7

Related Questions