【问题标题】:Clearing SectionsCollection in LiveCharts for WPF清除 WPF LiveCharts 中的 SectionsCollection
【发布时间】:2018-05-04 00:27:32
【问题描述】:

我正在使用 LiveCharts 的 Geared 版本构建 WPF 数据可视化工具。 我有一个名为 SectionsCollection 的 SectionsCollection 对象,我需要在数据更改时重新加载它。在重新分配给 SectionsCollection 之前,我运行以下代码段。

        try
        {
            if (SectionsCollection != null && SectionsCollection.Count > 0)
            {
                SectionsCollection.Clear();
            }
        }
        catch(Exception e)
        {
            Status += "Error in clearing SectionsCollection.\n"+e;
        }
        SectionsCollection = new SectionsCollection();

SectionsCollection.Clear(); 行间歇性发生以下错误,标签为 NullReferenceException occurred

Exception thrown: 'System.NullReferenceException' in LiveCharts.Wpf.dll

Additional information: Object reference not set to an instance of an object.

如果我检查SectionsCollection 不为空且不为空,为什么会出现此错误?

VisualsCollection 和 SeriesCollection 类型似乎也会出现此错误。

【问题讨论】:

  • 我也有同样的问题。你有没有发现如何让它工作?谢谢。

标签: wpf livecharts


【解决方案1】:

尝试添加标志以防止不需要的多个 exec。在你的过程中:

 bool collIsBusy = false;
        try
        {
            if (SectionsCollection != null && SectionsCollection.Count > 0 && !collIsBusy)
            {
                collIsBusy = true; //flag to prevent throttling multiple executions
                SectionsCollection.Clear();
                collIsBusy = false;
            }
        }
        catch (Exception e)
        {
            Status += "Error in clearing SectionsCollection.\n" + e;
        }
        SectionsCollection = new SectionsCollection();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 2014-01-13
    相关资源
    最近更新 更多