This is a migrated thread and some comments may be shown as answers.

Binding Visibility on LineSeries

3 Answers 209 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 25 Jan 2012, 01:29 AM
I am using a converter to bind the visibility of a LineSeries to a bool that is updated by a checkbox outside the ChartView.  Unfortunately, doing so throws NullReferenceExceptions, source code is below:

<telerik:RadCartesianChart Grid.Row="1">
            <chartview:LineSeries ItemsSource="{Binding PropertyValues.BPOs}"
                                  ValueBinding="BPO"
                                  CategoryBinding="Dt"
                                  Visibility="{Binding BPOsVisible, Converter={StaticResource BoolToVisibilityConverter}}">
               </chartview:LineSeries>
            <telerik:RadCartesianChart.HorizontalAxis>
                <chartview:DateTimeContinuousAxis LabelFitMode="MultiLine"
                                                  LabelFormat="MMM yyyy"/>
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <chartview:LinearAxis />
            </telerik:RadCartesianChart.VerticalAxis>
</telerik:RadCartesianChart>

public class PropertyValues
    {
        public List<BPOValue> BPOs { get; set; }
    }

    public class BPOValue
    {
        public DateTime Dt { get; set; }
        public decimal? BPO { get; set; }
        public string BPOType { get; set; }
    }

public class BoolToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool? b = value as bool?;
            if (b.HasValue)
            {
                if (b.Value)
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
            else
                return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion
    }

The NullReferenceException is being thrown after the Converter is passing back it's value and my graph renders fine when the visibility binding is removed.  Does the Visibility property not work as I am expecting (binding a Visibility object will change the state of the line), or am I using the property wrong?  Any help would be greatly appreciated!

Thanks!

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 27 Jan 2012, 05:11 PM
Hi Tyler,

Please, find attached a small example, based on your code, which shows a line series with visibility bound to a checkbox.

Best regards,
Ves
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Accepted
Luke
Top achievements
Rank 1
answered on 29 Jan 2012, 11:11 PM
Hi Ves,

I've noticed a very similar issue before.  If you take your solution, change the private field _BPOsVisible so that it is false to start with and then run it, you will get a NullReferenceException thrown from within RadChartBase.ArrangeOverride.

The problem is not the binding on the Visibility.  It seems the problem is that RadCartesianChart doesn't like being initialised with a collapsed series.  In fact, the following XAML is sufficient to reproduce the problem:

        <telerik:RadCartesianChart xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
           <telerik:LineSeries Visibility="Collapsed" />
        </telerik:RadCartesianChart>

The workaround for Tyler is to set up the Visibility binding in code-behind.  If the RadCartesianChart is within a UserControl, a suitable place to set up the binding is in an event handler for the UserControl's Loaded event.

I apologise for not filing a bug report about this.  My account has been added to a support contract which has expired, but despite me chasing my client several times, it still hasn't been renewed.
0
Ves
Telerik team
answered on 02 Feb 2012, 10:37 AM
Hi Luke,

Thanks for the heads up. I have logged the problem here. Hope setting it in code behind is applicable.

Best regards,
Ves
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ChartView
Asked by
Tyler
Top achievements
Rank 1
Answers by
Ves
Telerik team
Luke
Top achievements
Rank 1
Share this question
or