Toggle Series PointTemplate with CheckBox?

3 posts, 0 answers
  1. Andrew
    Andrew avatar
    8 posts
    Member since:
    Jul 2011

    Posted 01 Mar 2012 Link to this post

    I have a RadCartesianChart in my app and I would like to add a checkbox that would allow me to toggle the PointTemplate on or off for each of the Series in my chart.I tried updating the PointTemplate using the following but the ellipses never appear.

    void checkBoxShowDots_Click(object sender, RoutedEventArgs e)
    {
        foreach (ScatterLineSeries cs in radCartesianChart1.Series)
        {
            if ((bool)checkBoxShowDots.IsChecked)
            {
                    string Text = string.Format(
                        "<Ellipse Height=\"6\" Width=\"6\" Fill=\"{0}\" />"
                            , (cs.Stroke as SolidColorBrush).Color.ToString()
                        );
                    cs.PointTemplate = CreateDataTemplate(Text);
            }
            else
            {
                cs.PointTemplate = null;
            }
            cs.InvalidateMeasure();
        }
    }

    How can I achieve this behavior?
  2. Andrew
    Andrew avatar
    8 posts
    Member since:
    Jul 2011

    Posted 05 Mar 2012 Link to this post

    Update:
    I figured out how to do this. I had to create a UIHelper object which implements INotifyPropertyChanged and has a PointTemplate property. I then added a binding to the LineSeries to bind to this property. My Click handler then just goes and then sets the PointTemplate for each UIHelper object.

    However....

    It seems that if you start off with a null value for the PointTemplate property of the LineSeries, if you try to then assign a new value to that property after the chart has been rendered the new PointTemplate change is never registered. But if I start off with a value for PointTemplate, I can switch back and forth between that and a null value and the points will appear/disappear as expected. I worked around this by defining a PointTemplate that doesn't actually display anything instead of using a null value.

    Seems like a bug or at least behavior that should be documented. 
  3. DevCraft banner
  4. Sia
    Admin
    Sia avatar
    667 posts

    Posted 06 Mar 2012 Link to this post

    Hello Andrew,

    Thank you for the provided feedback. We will check the issue locally and let you know what causes it.

    Kind regards,
    Sia
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top