Binding xaml to DataSeries

3 posts, 0 answers
  1. Mathew Tonsager
    Mathew Tonsager avatar
    5 posts
    Member since:
    Apr 2010

    Posted 08 Apr 2010 Link to this post

    Hello,

    I would like to thank you in advance for reading this!

    Is there a way to bind the DataSeries data to a property when customizing a BarSeries/LineSeries style?

    I know you can do this if the data is set at the ItemSource level, but what about the DataSeries level?

    Ex:

    <Style x:Key="BarSeriesStyle" TargetType="telerikCharting:Bar">  
            <Setter Property="Template">  
                <Setter.Value> 
                    <ControlTemplate TargetType="telerikCharting:Bar">  
                        <Canvas> 
                            <Rectangle x:Name="PART_DefiningGeometry" 
                                  Height="{TemplateBinding ItemActualHeight}" 
                                  Width="{TemplateBinding ItemActualWidth}" 
                                  RadiusX="2" 
                                  RadiusY="2" 
                                  Fill="Pink" 
                                  Stroke="{Binding DataItem.GradeColor}" 
                                  StrokeThickness="3"  /> 
                        </Canvas> 
                        <ControlTemplate.Triggers> 
                            <Trigger Property="IsMouseOver" Value="true">  
                                <Setter TargetName="PART_DefiningGeometry" Property="Fill" Value="{StaticResource LightBrush}"/>  
                                <Setter TargetName="PART_DefiningGeometry" Property="Stroke" Value="{StaticResource LightBrush}"/>  
                                <!--<Setter TargetName="Border" Property="SnapsToDevicePixels" Value="true"/>--> 
                            </Trigger> 
                        </ControlTemplate.Triggers> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 

    Notice the line Stroke="{Binding DataItem.GradeColor}" 

    How would I bind this to a DataSeries set of information as opposed to the ItemSource set of information?

    Thanks,
    Matt
  2. Mathew Tonsager
    Mathew Tonsager avatar
    5 posts
    Member since:
    Apr 2010

    Posted 08 Apr 2010 Link to this post

    Hi again,

    I think I have figured out why the (Stroke="{Binding DataItem.GradeColor}") binding is not working. The DataItem is not being set when I add the DataSeries using VB code.

    I am trying to add a DataSeries manually in code like this:

    Dim ds As New DataSeries()  
            ds.Definition = New BarSeriesDefinition()  
            For Each person As Person In studentList  
                ds.Add(New DataPoint(person.Name, person.Grade))  
            Next 

    Then add the DataSeries to the RadChart like this:

    RadChart1.DefaultView.ChartArea.DataSeries.Add(ds) 

        
    So, naturally my binding won't work because my DataItem is not set for the DataSeries.

    See attached picture!

    How do I set the DataItem in VB for each DataSeries I create?

    Thanks,
    Matt

  3. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 14 Apr 2010 Link to this post

    Hi Mathew Tonsager,

    Simply set the DataItem property to the instance of your DataPoint to the data object you require.

    Kind regards,
    Vladimir Milev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top