uno 平台:在 UserControl 中,如何使绘制动作无效
uno platform: in UserControl, how do I invalidate to cause a paint action
在 Uno 中,我有一个 UserControl
和一些 属性 setter。当 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>
这是来自 c# 代码隐藏的一些片段:
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)
{
}
}
}
SKXamlCanvas
不会自行失效,除非它的大小或屏幕的 DPI 发生变化。
要强制失效,您需要为您的 canvas:
命名
<skia:SKXamlCanvas x:Name="canvas" PaintSurface="OnPaintSurface" />
然后使其无效:
public string Source
{
get => (string)GetValue(SourceProperty);
set
{
SetValue(SourceProperty, value);
canvas.Invalidate();
}
}
您可以查看 this here 的来源。
在 Uno 中,我有一个 UserControl
和一些 属性 setter。当 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>
这是来自 c# 代码隐藏的一些片段:
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)
{
}
}
}
SKXamlCanvas
不会自行失效,除非它的大小或屏幕的 DPI 发生变化。
要强制失效,您需要为您的 canvas:
命名 <skia:SKXamlCanvas x:Name="canvas" PaintSurface="OnPaintSurface" />
然后使其无效:
public string Source
{
get => (string)GetValue(SourceProperty);
set
{
SetValue(SourceProperty, value);
canvas.Invalidate();
}
}
您可以查看 this here 的来源。