Search code examples
androidxamarinxamarin.formsskiasharp

How to combine SKCanvasView with other views in the same page?


I am trying to show a SKCanvasView and other views like ListView or Labels on the same Page of a Xamarin Form project for Android.

My Xaml code:

<?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"
             x:Class="AndroidExample.Principal"
             Title="myApp">

  <StackLayout Orientation="Vertical">
      <skia:SKCanvasView x:Name="canvas" PaintSurface="Canvas_Paint_Surface"/>
      <Label Text="EXAMPLE" FontSize="Large" FontAttributes="Bold"/>
  </StackLayout>

</ContentPage>

It does not show anything when I deploy the App. Labeland SKCanvasVieware hidden or something like that.

I have also tried without using StackLayout, with same results :(


Solution

  • Use a grid instead

    <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"
                     x:Class="AndroidExample.Principal"
                     Title="myApp">
    
          <Grid>
              <skia:SKCanvasView x:Name="canvas" PaintSurface="Canvas_Paint_Surface"/>
              <Label Text="EXAMPLE" FontSize="Large" FontAttributes="Bold"/>   
         </Grid>
    
    </ContentPage>
    

    With this, your SKCanvasView will fill the entire view and you can place any controls above. A StackLayout stacks items. With your current code, SKCanvasView has Height =0;