dimanche 3 décembre 2017

C# WPF - Checkbox checked/unchecked events not working properly

I am using the checked event to assign values from a List held within a Dictionary to an XyDataSeries which is then set as the DataSeries for the chart to plot data. The below works and plots the data requested upon checking the box.

private void chkbx_Checked(object sender, RoutedEventArgs e)
{
    var list = dict["ListName"];
    var xyseries = new XyDataSeries<double, double>();
    foreach (var i in list)
    {
        var d = Convert.ToDouble(i);
        xyseries.Append(one++, d);
    }
    chartseries.DataSeries = xyseries;
}

I then have the unchecked event to clear the DataSeries for the chart using the Clear method. This removes the data from the chart as expected, or atleast the chart is cleared;

private void chkbx_Unchecked(object sender, RoutedEventArgs e)
{
    chartseries.DataSeries.Clear();
}

However when I check the box for a second time, the data does not appear again and I don't understand why.

I have tried setting chartseries to both null and zero explicitly with no change in results.

I have also tried declaring xyseries outside of the event and clearing that in the unchecked event also, but this instead resulted in the data not clearing upon unchecking of the box.




Aucun commentaire:

Enregistrer un commentaire