Reputation: 2372
I know a SkiaSharp
canvas can be placed in a Grid
in a Xamarin App. Here is some example (working) code:
xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
<skia:SKCanvasView
x:Name="AUView"
Grid.Row="2"
PaintSurface="AUView_PaintSurface" />
But when I try to do a similar thing in a WPF App:
xmlns:skia="clr-namespace:SkiaSharp;assembly=SkiaSharp"
<skia:SKCanvas
Name="AUView"
Grid.Row="2"
PaintSurface="AUView_PaintSurface" />
I get the error:
A value of type 'SKCanvas' cannot be added to a collection or dictionary of type 'UIElementCollection'.
Is it possible to put an SKCanvas
in a grid cell in WPF or does the whole of the page have to be an SKCanvas
?
Else, how/can you use SkiaSharp
in WPF?
Upvotes: 5
Views: 7745
Reputation: 22119
First, you have to install the SkiaSharp.Views.WPF
package, which will automatically install SkiaSharp
, too. The SkiaSharp
package alone will not contain the needed WPF control, which is SKElement
.
As it is a FrameworkElement
, you can place it anywhere in your view. SKCanvas
is not a WPF compatible component. To use an SKElement
in your XAML, you have to pull in its XML namespace.
xmlns:skia="clr-namespace:SkiaSharp.Views.WPF;assembly=SkiaSharp.Views.WPF"
Then place the SKCanvas
control anywhere in your view.
<skia:SKElement
Name="AUView"
Grid.Row="2"
PaintSurface="AUView_PaintSurface"/>
Upvotes: 13