QualitativeRange Error on Binding

5 posts, 0 answers
  1. Ralf
    Ralf avatar
    10 posts
    Member since:
    Nov 2010

    Posted 25 Jan 2011 Link to this post

    Hello,

    in my scenario i try to visualize the variance of a production cyle within a radgridview. For this i want to show a warning/error range.

    <telerik:RadHorizontalBulletGraph Width="150" Height="20"
                                      QuantitativeScaleVisibility="Collapsed"
                                      FlowDirection="LeftToRight"
                                      FeaturedMeasure="{Binding Input0TimeLast}"
                                      ComparativeMeasure="{Binding Auftrag.ZyklusIstSoll}">
         
        <telerik:RadHorizontalBulletGraph.QualitativeRanges>
            <telerik:QualitativeRange Brush="Red" Value="{Binding ZyklusErrorBound}" />
            <telerik:QualitativeRange Brush="Yellow" Value="{Binding ZyklusWarningBound}" />
            <telerik:QualitativeRange Brush="Green" Value="{Binding ZyklusOkBound" />
        </telerik:RadHorizontalBulletGraph.QualitativeRanges>
    </telerik:RadHorizontalBulletGraph>

    public int ZyklusErrorBound
    {
        get
        {
            var x = this.Auftrag.ZyklusIstSoll - this.Auftrag.ZyklusIstToleranz;
             
            return x;
        }
    }
    public int ZyklusWarningBound
    {
        get
        {
            var x = this.Auftrag.ZyklusIstSoll - (this.Auftrag.ZyklusIstToleranz / 2);
             
            return x;
        }
    }


    When i bind the three QualitativeRange`s i get a exception "Sequence contains no elements". If i set instead of ZyklusOkBound a fixed value for example, no exceptions is thrown. But the two other values are not called from my Itemssource (i´ve checked that by setting a breakpoint on my getters). Instead of a message shows up in my console:

    System.Windows.Data Error: 2 : Cannot find govening FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ZyklusWarningBound; DataItem=null; target element is 'QualitativeRange' (HashCode=7579691); target property is 'Value' (type 'Double')
    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ZyklusErrorBound; DataItem=null; target element is 'QualitativeRange' (HashCode=7579691); target property is 'Value' (type 'Double')

    What is absolutely remarkable, if i bind ZyklusErrorBound or ZyklusWarningBound to FeaturedMeasure the value is retrieved..

    Thanks in advance for your help.
  2. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 28 Jan 2011 Link to this post

    Hello Ralf,

    Check this xbap example here (BulletGraph -> FirstLook) -- you can bind the qualitative ranges like this:

    <telerik:RadGridView Name="RadGridVeiw1" telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True" AutoGenerateColumns="False" IsReadOnly="True" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" CanUserFreezeColumns="False" ItemsSource="{Binding Data}">
        <telerik:RadGridView.Columns>
     
            ...
         
            <telerik:GridViewDataColumn Header="% of YTD target" IsFilterable="False">
                <telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Height="20">
                            <Grid Width="45">
                                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding PercentYTDTargetText}" />
                            </Grid>
                            <telerik:RadHorizontalBulletGraph Width="150" Maximum="2"
                                                              QuantitativeScaleVisibility="Collapsed"
                                                              ComparativeMeasure="1"
                                                              FeaturedMeasure="{Binding PercentYTDTarget}"
                                                              QualitativeRanges="{Binding Ranges}" />
                        </StackPanel>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellTemplate>
            </telerik:GridViewDataColumn>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>


    Greetings,
    Bart.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ralf
    Ralf avatar
    10 posts
    Member since:
    Nov 2010

    Posted 31 Jan 2011 Link to this post

    Hi Bart,

    thank you for your answer. I had already taken a look to BulletGraph/FirstLook example.
    In this a collection is created code behind. But in this case i use the MVVM pattern and
    i don`t want to use references (for QualitativeRangeCollection) to my controls in the model view.

    In the BulletGraph/Configurator example you can see that there is a other approach and i assume
    that there binding should be possible.

    <telerik:RadVerticalBulletGraph Grid.Column="0"
        Grid.RowSpan="2"
        x:Name="VerticalBulletGraph"
        Minimum="0"
        Maximum="100"
        FeaturedMeasure="{Binding Value,ElementName=FeaturedSlider}"
        ComparativeMeasure="{Binding Value,ElementName=ComparativeSlider}"
        ProjectedValue ="{Binding Value,ElementName=ProjectedSlider}"
        VerticalAlignment="Stretch"
        HorizontalAlignment="Center"
        Width="60"
        Margin="15"
        AutoRange="false">
     
        <telerik:RadVerticalBulletGraph.QualitativeRanges>
            <telerik:QualitativeRangeCollection>
                <telerik:QualitativeRange Value="50" />
                <telerik:QualitativeRange Value="70" />
                <telerik:QualitativeRange />
            </telerik:QualitativeRangeCollection>
        </telerik:RadVerticalBulletGraph.QualitativeRanges>
    </telerik:RadVerticalBulletGraph>

    Greetings

    Ralf
  5. Ralf
    Ralf avatar
    10 posts
    Member since:
    Nov 2010

    Posted 01 Feb 2011 Link to this post

    Hello all,

    i found a solution after i realized that a direct binding of values seems not to be possible. Instead of that i use a MutlivalueConverter to return a QualitativeRangeCollection. Works like a charm.

    <telerik:RadHorizontalBulletGraph.QualitativeRanges>
        <MultiBinding Converter="{StaticResource ZyklusBoundsConverter}">                                           
            <Binding Path="Auftrag.ZyklusErrorBound" />
            <Binding Path="Auftrag.ZyklusWarningBound" />
            <Binding Path="Auftrag.ZyklusOkBound" />
        </MultiBinding>                                       
    </telerik:RadHorizontalBulletGraph.QualitativeRanges>

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        QualitativeRangeCollection qr = new QualitativeRangeCollection();
         
        var x1 = new QualitativeRange();
        x1.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
        x1.Value = System.Convert.ToDouble(values[0]);           
        qr.Add(x1);
     
        var x2 = new QualitativeRange();
        x2.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Yellow);
        x2.Value = System.Convert.ToDouble(values[1]);           
        qr.Add(x2);
     
        var x3 = new QualitativeRange();
        x3.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green);
        x3.Value = System.Convert.ToDouble(values[2]);           
     
        qr.Add(x3);
                     
         
        return qr;
    }

    -ralf
  6. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 02 Feb 2011 Link to this post

    Hello Ralf,

    Another approach could be to use binding with Source that overrides the value inherited by the DataContext. You can find more information in this topic in our forum.

    Hope you find this helpful!

    Greetings,
    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>>
Back to Top
UI for WPF is Visual Studio 2017 Ready