Uwp uno平台:在UserControl中,如何使绘制操作无效

Uwp uno平台:在UserControl中,如何使绘制操作无效,uwp,invalidation,skiasharp,uno-platform,Uwp,Invalidation,Skiasharp,Uno Platform,在Uno中,我有一个带有一些属性设置器的UserControl。当setter被调用时,我需要使控件被绘制,即无效。什么方法可以做到这一点 我尝试了Invalidate(true),它应该适用于UWP,但不适用于Uno。我还尝试了InvalidateSurface(),也没有被识别 我正在使用SkiaSharp进行图形处理 以下是我对控件的xaml: <UserControl x:Class="UnoTest.Shared.Controls.ExpandableImage&q

在Uno中,我有一个带有一些属性设置器的
UserControl
。当setter被调用时,我需要使控件被绘制,即无效。什么方法可以做到这一点

我尝试了
Invalidate(true)
,它应该适用于UWP,但不适用于Uno。我还尝试了
InvalidateSurface()
,也没有被识别

我正在使用SkiaSharp进行图形处理

以下是我对控件的xaml:

<UserControl
  x:Class="UnoTest.Shared.Controls.ExpandableImage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:UnoTest.Shared.Controls"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:skia="using:SkiaSharp.Views.UWP"
  >

  <skia:SKXamlCanvas PaintSurface="OnPaintSurface" />
  
</UserControl>

SKXamlCanvas
不会使其自身失效,除非其大小或屏幕的DPI发生变化

要强制无效,您需要为画布指定一个名称:


然后将其作废:

公共字符串源
{
get=>(字符串)GetValue(SourceProperty);
设置
{ 
SetValue(SourceProperty,value);
canvas.Invalidate();
}
}

您可以查看的源。

除非其大小或屏幕的DPI发生变化,否则
SKXamlCanvas
不会使其自身失效

要强制无效,您需要为画布指定一个名称:


然后将其作废:

公共字符串源
{
get=>(字符串)GetValue(SourceProperty);
设置
{ 
SetValue(SourceProperty,value);
canvas.Invalidate();
}
}
您可以查看的源代码

using SkiaSharp;
using SkiaSharp.Views.UWP;
using System.IO;
using System.Reflection;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace UnoTest.Shared.Controls
{
  public sealed partial class ExpandableImage : UserControl
  {
    ...
    public string Source
    {
      get { return (string)GetValue(SourceProperty); }
      set 
      { 
        SetValue(SourceProperty, value);
        // invalidate here
      }
    }
    ...
    private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
    {
    }
  }
}