-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChartCanvas.cs
44 lines (37 loc) · 1.21 KB
/
ChartCanvas.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Microcharts;
using Microsoft.UI.Xaml;
using SkiaSharp.Views.Windows;
namespace XamlBrewer.WinUI.Controls
{
/// <summary>
/// A SkiaSharp WinUI Canvas that draws a Microcharts Chart.
/// </summary>
public class ChartCanvas : SKXamlCanvas
{
public static readonly DependencyProperty ChartProperty =
DependencyProperty.Register(nameof(Chart), typeof(Chart), typeof(ChartCanvas), new PropertyMetadata(null));
public Chart Chart
{
get { return (Chart)GetValue(ChartProperty); }
set
{
if (Chart != null)
{
Chart.PropertyChanged -= (o, e) => { Invalidate(); };
}
SetValue(ChartProperty, value);
Invalidate();
if (Chart != null)
{
Chart.PropertyChanged += (o, e) => { Invalidate(); };
}
}
}
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
e.Surface.Canvas.Clear();
Chart?.DrawContent(e.Surface.Canvas, e.Info.Width, e.Info.Height);
base.OnPaintSurface(e);
}
}
}