Point Marks and RadContext menu fail

5 posts, 0 answers
  1. MikeWiese
    MikeWiese avatar
    41 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"
        ShowItemLabels="False" 
        ShowItemToolTips="True"
        PointMarkItemStyle="{StaticResource AveragePointMarkStyle}">
    </telerik:LineSeriesDefinition>

    And the AveragePointMarkStyle is defined as follows:

    <Style x:Key="AveragePointMarkStyle"  TargetType="telerik:PointMark">
        <Setter Property="Size" Value="7" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="telerik:PointMark">
                    <Canvas>
                        <Path x:Name="PART_PointMarkPath"
                              Stretch="Fill"
                              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.ContextMenu>
                            <telerik:RadContextMenu ItemsSource="{Binding DataItem.MenuItems,Mode=OneWay}"
                                                    ItemClick="OnContextMenuClick"
                                                    MaxWidth="185"
                                                    Placement="MousePoint"
                                                    MinWidth="130"
                                                    Tag="{Binding DataItem}">
                            </telerik:RadContextMenu>
                        </telerik:RadContextMenu.ContextMenu>
                        </Path>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    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
    Admin
    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,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. MikeWiese
    MikeWiese avatar
    41 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.
  5. 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.
  6. Yavor
    Admin
    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:

    <telerik:LineSeries.PointTemplate>
        <DataTemplate>
            <Ellipse Width="10" Height="10" Fill="Red">
                <Ellipse.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Item 1" />
                        <MenuItem Header="Item 2" />
                    </ContextMenu>
                </Ellipse.ContextMenu>
            </Ellipse>
        </DataTemplate>
    </telerik:LineSeries.PointTemplate>

    Please check the attached demo.

    Regards,
    Yavor
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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
DevCraft banner