Dynamic Visibility
View model
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.General.Visibility;
public partial class ViewModel
{
public ISeries[] Series { get; set; } = [
new ColumnSeries<double>
{
Values = [2, 5, 4, 3],
IsVisible = true
},
new ColumnSeries<double>
{
Values = [6, 3, 2, 8],
IsVisible = true
},
new ColumnSeries<double>
{
Values = [4, 2, 8, 7],
IsVisible = true
}
];
[RelayCommand]
public void ToggleSeries0() =>
Series[0].IsVisible = !Series[0].IsVisible;
[RelayCommand]
public void ToggleSeries1() =>
Series[1].IsVisible = !Series[1].IsVisible;
[RelayCommand]
public void ToggleSeries2() =>
Series[2].IsVisible = !Series[2].IsVisible;
}
using Eto.Forms;
using LiveChartsCore.SkiaSharpView.Eto;
using ViewModelsSamples.General.Visibility;
namespace EtoFormsSample.General.Visibility;
public class View : Panel
{
private readonly CartesianChart cartesianChart;
public View()
{
var viewModel = new ViewModel();
cartesianChart = new CartesianChart
{
Series = viewModel.Series,
};
var b1 = new Button { Text = "toggle 1" };
b1.Click += (object sender, System.EventArgs e) => viewModel.ToggleSeries0();
var b2 = new Button { Text = "toggle 2" };
b2.Click += (object sender, System.EventArgs e) => viewModel.ToggleSeries1();
var b3 = new Button { Text = "toggle 3" };
b3.Click += (object sender, System.EventArgs e) => viewModel.ToggleSeries2();
var buttons = new StackLayout(b1, b2, b3) { Orientation = Orientation.Horizontal, Padding = 2, Spacing = 4 };
Content = new DynamicLayout(buttons, cartesianChart);
}
}
Articles you might also find useful: