Binding entity to the command parameter in RadCartesianChart

2 posts, 0 answers
  1. Tommi
    Tommi avatar
    1 posts
    Member since:
    May 2014

    Posted 11 Jul 2014 Link to this post

    I would like to bind entity from the itemsource collection to the command parameter.

    My goal is to open certain entity when it is clicked from the grid, but have unable to bind
    the entity from the binded collection.

    Is this possible to do by using MVVM approach?
    One challenge is that I have two telerik:BarSeries defined for the chart.

    So this code line at the below needs to be sorted out,

    Here is the full code:

    <telerik:RadCartesianChart Margin="10" IsHitTestVisible="True">

                    <telerik:CartesianChartGrid MajorLinesVisibility="XY" MajorXLinesRenderMode="All">

                    <telerik:DateTimeContinuousAxis MajorStepUnit="Minute" MajorTickStyle="{StaticResource MajorTickStyle}" PlotMode="OnTicksPadded">
                                <TextBlock Text="{Binding}"></TextBlock>
                    <telerik:LinearAxis Minimum="0" Maximum="200" ShowLabels="False"></telerik:LinearAxis>

                <telerik:BarSeries ItemsSource="{Binding EntityData1}" ValueBinding="EntityTime" CategoryBinding="EntityTakingTime" Height="1000">
                            <Rectangle x:Name="RectangleGreen" Fill="Green" MaxWidth="20"/>

                <telerik:BarSeries ItemsSource="{Binding EntityData2}" ValueBinding="EntityTime" CategoryBinding="EntityTakingTime" Height="1000">
                            <Rectangle x:Name="RectangleRed" Fill="Red" MaxWidth="20"/>

                    <telerik:EventBinding Command="{Binding OpenEntityCommand}" 
                                          CommandParameter="???????????????" />


    Check the attached screenshot to see the generated chart.
    Green and red bars should work as links to open certain entity.

    Best Regards, Tommi

  2. Petar Marchev
    Petar Marchev avatar
    999 posts

    Posted 14 Jul 2014 Link to this post

    Hi Tommi,

    The wpf framework does not allow a binding in the CommandParameter because the Binding object is not a DependencyObject and the CommandParameter property is not a DependencyProperty. Perhaps you can simply attach an event handler to the MouseLeftButtonDown event of the series, set the IsHitTestVisible property of the series to true and in the event handler get the original source, get its data context (which is a DataPoint) and get the DataItem (which is the actual business item). Let us know how it goes.

    Petar Marchev
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top