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

Binding Qualitative Range Causes Exception

1 Answer 113 Views
BulletGraph
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 26 Jan 2011, 05:21 PM
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:
    xmlns:local="clr-namespace:Report_Templates"
    mc:Ignorable="d"
    x:Class="Report_Templates.Bullet_View"
    Title="Bullet_View Page"
    d:DesignWidth="800" d:DesignHeight="600">
     
    <UserControl.DataContext>
        <local:MainViewModel/>
    </UserControl.DataContext>
     
    <Grid x:Name="LayoutRoot">
            <telerik:RadHorizontalBulletGraph Grid.Row="1"
            Minimum="0"
            Maximum="{Binding BulletAggregators[0].High}"
            FeaturedMeasure="{Binding BulletAggregators[0].Actual}"
            ComparativeMeasure="{Binding BulletAggregators[0].Goal}"
            Width="450"
            Height="50">
            <telerik:RadBulletGraphBase.QualitativeRanges>
                <telerik:QualitativeRange Brush="Red" Value="{Binding BulletAggregators[0].Median}"/>
                <telerik:QualitativeRange Brush="Yellow" Value="{Binding BulletAggregators[0].Mean}" />
                <telerik:QualitativeRange Brush="Green" />
            </telerik:RadBulletGraphBase.QualitativeRanges>
            </telerik:RadHorizontalBulletGraph>
    </Grid>
</sdk:Page>

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:
System.InvalidOperationException
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)
 
  
System.InvalidOperationException
[NoElements]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.51204.0&File=System.Core.dll&Key=NoElements
   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?

-Jonathan

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 31 Jan 2011, 09:42 AM
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:

<UserControl.Resources>
    <viewmodel:ExampleViewModel x:Key="dataContext" />
</UserControl.Resources>
 
<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}"
        Width="450"
        Height="50">
        <telerik:RadHorizontalBulletGraph.QualitativeRanges>
            <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" />
        </telerik:RadHorizontalBulletGraph.QualitativeRanges>
    </telerik:RadHorizontalBulletGraph>
</Grid>

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!


Regards,
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>>
Tags
BulletGraph
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or