This question is locked. New answers and comments are not allowed.
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!
<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!