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

QualitativeRange Error on Binding

4 Answers 123 Views
BulletGraph
This is a migrated thread and some comments may be shown as answers.
Ralf
Top achievements
Rank 1
Ralf asked on 25 Jan 2011, 03:06 PM
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.

4 Answers, 1 is accepted

Sort by
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 28 Jan 2011, 04:18 PM
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.
0
Ralf
Top achievements
Rank 1
answered on 31 Jan 2011, 09:26 AM
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
0
Ralf
Top achievements
Rank 1
answered on 01 Feb 2011, 08:34 AM
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
0
Yavor
Telerik team
answered on 02 Feb 2011, 10:09 AM
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>>
Tags
BulletGraph
Asked by
Ralf
Top achievements
Rank 1
Answers by
Bartholomeo Rocca
Top achievements
Rank 1
Ralf
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or