Wrap 3rd party controls
Describe how to create a wrapper for any control in order to use it inside your component
[Scaffold(typeof(LiveChartsCore.SkiaSharpView.Maui.CartesianChart))]
partial class CartesianChart { }
[Scaffold(typeof(LiveChartsCore.SkiaSharpView.Maui.PieChart))]
partial class PieChart { }
[Scaffold(typeof(LiveChartsCore.SkiaSharpView.Maui.CartesianChart))]
partial class CartesianChart { }
[Scaffold(typeof(LiveChartsCore.SkiaSharpView.Maui.PolarChart))]
partial class PolarChart { }
class ChartPageState
{
public double[] Values { get; set; } = new double[] { 2, 1, 2, 3, 2, 3, 3 };
}
class ChartPage : Component<ChartPageState>
{
static readonly Random _rnd = new();
public override VisualNode Render()
=> ContentPage("Chart Sample",
Grid("*, *, Auto", "*",
new PolarChart()
.Series(() => new ISeries[]
{
new PolarLineSeries<double>
{
Values = State.Values,
Fill = null,
IsClosed = false,
Stroke = new SolidColorPaint(SKColors.Blue) { StrokeThickness = 5 },
}
}),
new CartesianChart()
.Series(() => new ISeries[]
{
new LineSeries<double>
{
Values = State.Values,
Fill = null,
Stroke = new SolidColorPaint(SKColors.Green) { StrokeThickness = 2 },
}
})
.GridRow(1),
Slider()
.GridRow(2)
.Minimum(2)
.Maximum(25)
.Margin(5)
.Value(()=>State.Values.Length)
.OnValueChanged((s, args)=>
{
SetState(s => s.Values =
Enumerable.Range(1, (int)args.NewValue)
.Select(_=>_rnd.NextDouble()*20.0)
.ToArray(), false);
})
)
)
.BackgroundColor(Colors.Black);
}Last updated