Point Marks and RadContext menu fail

5 posts, 0 answers
  1. MikeWiese
    MikeWiese avatar
    43 posts
    Member since:
    Apr 2007

    Posted 08 Oct 2012 Link to this post

    I need to display a RadContextMenu when a user right-clicks on a pointmark on a line series. But the RadContextMenu always appears at (0,0), instead of the mouse-click location.

    My ChartView has a LineSeriesDefinition that sets the PointMarkItemStyle as follows:

    <telerik:LineSeriesDefinition EmptyPointBehavior="Drop"
        PointMarkItemStyle="{StaticResource AveragePointMarkStyle}">

    And the AveragePointMarkStyle is defined as follows:

    <Style x:Key="AveragePointMarkStyle"  TargetType="telerik:PointMark">
        <Setter Property="Size" Value="7" />
        <Setter Property="Template">
                <ControlTemplate TargetType="telerik:PointMark">
                        <Path x:Name="PART_PointMarkPath"
                              Width="{TemplateBinding Size}"
                              Height="{TemplateBinding Size}"
                              Style="{TemplateBinding ShapeStyle}"
                              Canvas.Left="{TemplateBinding PointMarkCanvasLeft}"
                              Canvas.Top="{TemplateBinding PointMarkCanvasTop}"
                              Stroke="{StaticResource PrimaryTargetLineBackground}" 
                              Fill="{StaticResource AverageLineBackground}"
                              Data="{Binding DataItem.Note,Mode=OneWay,Converter={StaticResource NoteExistPathDataConverter}}">
                            <telerik:RadContextMenu ItemsSource="{Binding DataItem.MenuItems,Mode=OneWay}"
                                                    Tag="{Binding DataItem}">

    This is all good, except that when I right-click on a point mark, the RadContextMenu opens in the (0,0) location of the screen, instead of where the right-click took place, which is unacceptable.

    I tried adding

    PlacementTarget="{Binding RelativeSource={RelativeSource Self}}"

    to the definition of the RadContextMenu. This causes the context menu to appear in the correct location, but it now contains no menu items because this somehow stuff up the ItemsSource binding - binding simply does not take place. And the documentation for the PlacementTarget property is really bad.

    Is this possible to make this work properly (i.e. the context menu appears in the correct place AND the ItemSource binds correctly) in a templated scenario?

  2. Giuseppe
    Giuseppe avatar
    2363 posts

    Posted 11 Oct 2012 Link to this post

    Hello Mike,

    We would suggest you to use the approach demonstrated in this online example here instead (customize the template of the Line element and not of the actual point mark). We have attached a runnable sample application for your reference.

    Hope this helps.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. MikeWiese
    MikeWiese avatar
    43 posts
    Member since:
    Apr 2007

    Posted 16 Oct 2012 Link to this post

    Thank you Giuseppe, I got it to work. I had some problems with an error "ItemsControl.Items must not be a UIelement type when an item template is set" . But I think this was because in my original code, the MenuItems collection it was binding to was a collection of RadMenuItem's. I changed it to bind to a collection of a simpler MenuItem type as per your sample code.
  4. Senthil kumar
    Senthil kumar avatar
    21 posts
    Member since:
    Sep 2013

    Posted 13 Nov 2013 Link to this post

    could you give me the sample for context menu in the radcartesian chart view.
  5. Yavor
    Yavor avatar
    401 posts

    Posted 14 Nov 2013 Link to this post

    Hi Senthil,

    Adding a context menu to the point marks in RadChartView is much simpler. Here is how:

            <Ellipse Width="10" Height="10" Fill="Red">
                        <MenuItem Header="Item 1" />
                        <MenuItem Header="Item 2" />

    Please check the attached demo.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top