SkiaSharp
SkiaSharp copied to clipboard
[BUG] `SKElement.InvalidateVisual()` does not update screen on WPF
Description
Graphics is not updated after calling SKElement.InvalidateVisual()
. But if I change Width property instead of this call, then graphics is updated
Code
Code example. x
changes, OnPaintSurface is called, but a circle doesn't move
using System;
using System.Timers;
using System.Windows;
using SkiaSharp;
using SkiaSharp.Views.Desktop;
public partial class MainWindow
{
private int x;
public MainWindow()
{
InitializeComponent();
var timer = new Timer(50);
timer.Elapsed += (_, _) => Dispatcher.Invoke(() =>
{
x += 10;
MainCanvas.InvalidateVisual();
});
timer.Start();
}
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
canvas.Clear(SKColors.Gainsboro);
using var fillBrush = new SKPaint();
fillBrush.IsAntialias = true;
fillBrush.Style = SKPaintStyle.Fill;
canvas.DrawCircle(x, 50, 20, fillBrush);
Console.WriteLine(x);
}
}
And xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wpf="clr-namespace:SkiaSharp.Views.WPF;assembly=SkiaSharp.Views.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<Grid>
<wpf:SKElement Name="MainCanvas" PaintSurface="OnPaintSurface" IgnorePixelScaling="True" />
</Grid>
</Window>
Version of SkiaSharp
2.88.3 (Current)
IDE / Editor
Rider
Platform / Operating System
Windows
Platform / Operating System Version
Windows 10
I also encountered this problem on some computers. Do you have any solution?