Dynamic Visibility
View model
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.General.Visibility;
[ObservableObject]
public partial class ViewModel
{
public ISeries[] Series { get; set; } =
{
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 2, 5, 4, 3 },
IsVisible = true
},
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 6, 3, 2, 8 },
IsVisible = true
},
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 4, 2, 8, 7 },
IsVisible = true
}
};
[ICommand]
public void ToggleSeries0()
{
Series[0].IsVisible = !Series[0].IsVisible;
}
[ICommand]
public void ToggleSeries1()
{
Series[1].IsVisible = !Series[1].IsVisible;
}
[ICommand]
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: