Binding Qualitative Range Causes Exception

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    2 posts
    Member since:
    Dec 2010

    Posted 26 Jan 2011 Link to this post

    I have a BulletGraph in a UserControl, and I'm trying to bind the values of the qualitative ranges to values in my ViewModel. I can bind maximum, featured, comparative, projected, minimum, and so on. But adding bound values to qualitative ranges generates an exception.

    My XAML code:
        Title="Bullet_View Page"
        d:DesignWidth="800" d:DesignHeight="600">
        <Grid x:Name="LayoutRoot">
                <telerik:RadHorizontalBulletGraph Grid.Row="1"
                Maximum="{Binding BulletAggregators[0].High}"
                FeaturedMeasure="{Binding BulletAggregators[0].Actual}"
                ComparativeMeasure="{Binding BulletAggregators[0].Goal}"
                    <telerik:QualitativeRange Brush="Red" Value="{Binding BulletAggregators[0].Median}"/>
                    <telerik:QualitativeRange Brush="Yellow" Value="{Binding BulletAggregators[0].Mean}" />
                    <telerik:QualitativeRange Brush="Green" />

    The values are all doubles, as here:
    _BulletAggregators.Add(new BulletAggregator() { Actual = 121.00, Low = 115.00, High = 188.00, Mean = 151.80, Median = 153.00, Current = 121.00, Goal = 119 });

    And the exception thrown:
    An unhandled exception was encountered while trying to render the current silverlight project on the design surface. To diagnose this failure, please try to run the project in a regular browser using the silverlight developer runtime.
       at Microsoft.Windows.Design.Platform.SilverlightViewProducer.OnUnhandledException(Object sender, ViewUnhandledExceptionEventArgs e)
       at Microsoft.Expression.Platform.Silverlight.SilverlightPlatformSpecificView.OnUnhandledException(Object sender, ViewUnhandledExceptionEventArgs args)
       at Microsoft.Expression.Platform.Silverlight.Host.SilverlightImageHost.<>c__DisplayClass1.<Application_UnhandledException>b__0(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
    Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See
       at System.Linq.Enumerable.Min(IEnumerable`1 source)
       at Telerik.Windows.Controls.BulletGraph.RadBulletGraphBase.CalculateDataRange(Double& dataMin, Double& dataMax) in c:\Builds\WPF_Scrum\Release_SL_2010_Q3\Sources\Development\Controls\DataVisualization\BulletGraph\Base\RadBulletGraphBase.cs:line 676
       at Telerik.Windows.Controls.BulletGraph.RadBulletGraphBase.ReCalculateRange() in c:\Builds\WPF_Scrum\Release_SL_2010_Q3\Sources\Development\Controls\DataVisualization\BulletGraph\Base\RadBulletGraphBase.cs:line 786
       at Telerik.Windows.Controls.BulletGraph.RadBulletGraphBase.OnLayoutUpdated(Object sender, EventArgs e) in c:\Builds\WPF_Scrum\Release_SL_2010_Q3\Sources\Development\Controls\DataVisualization\BulletGraph\Base\RadBulletGraphBase.cs:line 752
       at System.Windows.FrameworkElement.OnLayoutUpdated(Object sender, EventArgs e)
       at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)

    When I run the application, the BulletGraph simply doesn't appear. Is there a better way to add qualitative ranges with bound values?

  2. Yavor
    Yavor avatar
    401 posts

    Posted 31 Jan 2011 Link to this post

    Hello Jonathan,

    The problem that you face is caused by the way the DataContext is inherited by the children in the visual tree. QualitativeRanges is a collection and its children are not inheriting its DataContext, so the binding expression for the Value property will return NaN (the default value for double). This causes all qualitative ranges to have value = NaN and thats why the exception occurs. Our developers have fixed this issue and when all qualitativeranges have value = NaN no exception will be thrown. You can change the way the DataContext is inherited by moving your view model to the Resources of the UserControl and identifying it with its key as the Source of the Binding expression like this:

        <viewmodel:ExampleViewModel x:Key="dataContext" />
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadHorizontalBulletGraph x:Name="bulletGraph" Minimum="0"
            Maximum="{Binding Source={StaticResource dataContext}, Path=BulletAggregators[0].High}"
            FeaturedMeasure="{Binding Source={StaticResource dataContext}, Path=BulletAggregators[0].Actual}"
            ComparativeMeasure="{Binding BulletAggregators[0].Goal}"
                <telerik:QualitativeRange Brush="Red" Value="{Binding Source={StaticResource dataContext}, Path=BulletAggregators[0].Median}" />
                <telerik:QualitativeRange Brush="Yellow" Value="{Binding Source={StaticResource dataContext}, Path=BulletAggregators[0].Mean}" />
                <telerik:QualitativeRange Brush="Green" />

    I have noticed another potential issue. QualitativeRanges have to be specified always in increasing order. So your Median has to be lower than Mean value, because these ranges are always drawn from the start of the scale and you are specifying the end of each range.

    Hope this helps!

    Yavor Ivanov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft R3 2016 release webinar banner
Back to Top