c# - 使用 c#/WPF/livecharts。如何在 SeriesCollection 中设置单个项目的可见性?
问题描述
我正在为我的图表系列使用 SeriesCollection。
我想要做的是当用户在系列列表中选中/取消选中时切换可见性。
在 XAML 中,ItemsControl 代码是这样的。
<ItemsControl ItemsSource="{Binding Path=SeriesItemList}"
ItemTemplate="{StaticResource toggleChartItemTemplate}"
>
在项目模板中,复选框 IsChecked 事件是这样绑定的。
<CheckBox IsChecked="{Binding Path=IsChecked}" >
</CheckBox>
当 IsChecked 被调用时,它被写在类文件中
public bool IsChecked
{
get { return _IsChecked; }
set
{
_IsChecked = value;
Console.Write("");
mainViewModel.ToggleSeries(SeriesName, value);
RaisePropertyChanged("IsChecked");
}
}
最后,调用了 ToggleSeries 函数
public void ToggleSeries(string SeriesName, bool value)
{
for (int idx = 0; idx < MainChartSeries.Count; idx++)
{
if (MainChartSeries[idx].Title == SeriesName)
{
//We will set visibility of the series here.
}
}
Console.Write("");
}
代码可以正常工作。所以我认为没有问题。如果我能找出如何设置 SeriesCollection 的单个系列可见性的可见性。
我可以访问的是 IsSeriesVisible 属性。它没有设置方法。
如何设置它的可见性?我应该将 SeriesCollection 更改为其他内容吗?
谢谢你。
解决方案
刚刚遇到同样的问题并找到了解决方案。
您可以将您的SeriesCollection[idx]转换为您正在使用的系列,如下所示:
LineSeries seriesToHide = (MainChartSeries[idx] as LineSeries);
seriesToHide.Visibility = Visibility.Collapsed;
在那里,您拥有带有 setter 的 Visibility 属性,以及更多其他有用的属性。
推荐阅读
- redux-form - 如果特定输入具有值,则隐藏输入
- r - R函数使用前一行数据循环遍历新行
- javascript - 找到双 jquery.js 包含并删除它
- javascript - 根据当前页面或 URL 设置菜单活动
- java - 卡夫卡民意调查突然卡住了
- sqlite - 如何在 SQLite 中将日期 dd.mm.yyyy 的类型更改为 yyyy-mm-dd?
- sql-server - 从 Scala/Spark 写入 SQL Server 日期时间数据类型
- c# - 在 Docker 中运行 Blazor
- java - 无法从活动中停止 BaseAdapter 音频播放器
- python - 从最后一个没有for循环的情况下查找x变量的连续子序列