J'ai un Xamrin Form
avec la disposition de la grille comme indiqué ci-dessous. Il y a une toile SkiaSharp
avec une couleur dégradée. J'ai besoin d'ajouter un bouton à l'intérieur de la toile pour obtenir un arrière-plan dégradé. Mais quand j'ajoute un bouton dans le canevas, il ne rend rien (Button x: Name = "ClickMe2"). Quelle est la manière correcte d'obtenir un bouton rendu avec un arrière-plan dégradé?Le bouton Canvas SkiaSharp ne fonctionne pas
XAML
<Grid x:Name="controlGrid">
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<views:SKCanvasView PaintSurface="OnSecondPainting" EnableTouchEvents="True" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" >
<Button x:Name="ClickMe2" Text="ClickMe 2" HeightRequest="50" VerticalOptions="Start" />
</views:SKCanvasView>
<Label Text="Bottom Left" Grid.Row="1" Grid.Column="0" />
<Button x:Name="ClickMe1" Text="ClickMe 1" Grid.Row="1" Grid.Column="1" HeightRequest="50" VerticalOptions="Start" />
</Grid>
C#
private void OnSecondPainting(object sender, SKPaintSurfaceEventArgs e)
{
var surface = e.Surface;
var canvas = surface.Canvas;
canvas.Clear(SKColors.White);
///GRADIENT--------------------------------------------------------------------
var colors = new SKColor[] { new SKColor(6, 107, 249), new SKColor(27, 162, 210), new SKColor(36, 182, 197) };
var shader = SKShader.CreateLinearGradient(new SKPoint(300, 0), new SKPoint(300, 600), colors, null, SKShaderTileMode.Clamp);
var paint = new SKPaint() { Shader = shader };
canvas.DrawPaint(paint);
}
Je pense que vous devriez dessiner avec le chemin, comme DrawRect? –