This is a migrated thread and some comments may be shown as answers.

Point Marks and RadContext menu fail

4 Answers 31 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
MikeWiese
Top achievements
Rank 1
MikeWiese asked on 09 Oct 2012, 04:18 AM

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?

4 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 11 Oct 2012, 11:58 AM
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.

0
MikeWiese
Top achievements
Rank 1
answered on 16 Oct 2012, 01:13 PM
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.
0
Senthil kumar
Top achievements
Rank 1
answered on 13 Nov 2013, 09:47 AM
could you give me the sample for context menu in the radcartesian chart view.
0
Yavor
Telerik team
answered on 14 Nov 2013, 10:08 AM
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 >>
Tags
ChartView
Asked by
MikeWiese
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
MikeWiese
Top achievements
Rank 1
Senthil kumar
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or