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

    Hello,
    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,
    "CommandParameter="???????????????" 

    Here is the full code:


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

               <telerik:RadCartesianChart.Grid>
                    <telerik:CartesianChartGrid MajorLinesVisibility="XY" MajorXLinesRenderMode="All">
                    </telerik:CartesianChartGrid>
               </telerik:RadCartesianChart.Grid>

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

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

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

               <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding Command="{Binding OpenEntityCommand}" 
                                          EventName="MouseLeftButtonDown" 
                                          RaiseOnHandledEvents="True"
                                          CommandParameter="???????????????" />
                </telerik:EventToCommandBehavior.EventBindings>

    </telerik:RadCartesianChart>


    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
    Admin
    Petar Marchev avatar
    968 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.

    Regards,
    Petar Marchev
    Telerik
     
    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top