Hello,
I'm trying to set a simple context menu for an Axis within a XamDataChart:
<ig:XamDataChart Grid.Column="0" Grid.Row="1" x:Name="ColumnChart" Legend="{StaticResource Legend}" Padding="10" HorizontalZoomable="True"
HorizontalZoombarVisibility="Collapsed" VerticalZoomable="True" VerticalZoombarVisibility="Collapsed" >
<ig:XamDataChart.Axes> <ig:NumericYAxis x:Name="ColumnYAxis" MinimumValue="0" Interval="1" Label="{}{}"> <ig:NumericYAxis.ContextMenu> <ContextMenu> <MenuItem Header="Hola"></MenuItem> </ContextMenu> </ig:NumericYAxis.ContextMenu> </ig:NumericYAxis> <ig:CategoryXAxis x:Name="ColumnXAxis" ItemsSource="{Binding Path=Cat, Source={StaticResource EnergyProductionCollection}}"> </ig:CategoryXAxis> </ig:XamDataChart.Axes>
But when I right-click on the axis is not triggering. I tried attaching to the ContextMenuOpening event but it's not being triggered either. Could it be overriden by another event from another part of a control?
Thank you very much.
Sebastian
Hi Rob,
thanks a lot.
Regards Horst
Here's a running sample that shows this working.
5518.ContextMenuChartAxis.zip
Hi Horst,
The XAML should look pretty similar to my previous answer however instead of using the native WPF ContextMenu you'll switch it to the XamContextMenu. It would look like this:
<ig:NumericYAxis x:Name="yAxis"> <ig:NumericYAxis.LabelPanelStyle> <Style TargetType="{x:Type ig:VerticalAxisLabelPanel}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="ig:ContextMenuService.Manager"> <Setter.Value> <ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu> <ig:XamMenuItem Header="Font" /> <ig:XamMenuItem Header="Formatting" /> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </Setter.Value> </Setter> </Style> </ig:NumericYAxis.LabelPanelStyle> </ig:NumericYAxis>
I tried the above Code with a Project I am writing.
It works in the case above.
In my case I use ContextMenuManager and XamContextMenu in the grid containing the Chart which contains the axis.
Now I want the axis to Display a different XamContextMenu for the axis.
How would the XAML look in that case?
Hi Sebastian,
Place the context menu on the label panel used to render the axis labels. The NumericYAxis control doesn't actually render over the side axis area but rather it shows up on the chart plot area in order to draw the axis lines. We have a separate control which is responsible for rendering the axis labels off to the side.
<ig:NumericYAxis.LabelPanelStyle> <Style TargetType="{x:Type ig:VerticalAxisLabelPanel}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="Hola"></MenuItem> </ContextMenu> </Setter.Value> </Setter> </Style></ig:NumericYAxis.LabelPanelStyle>
The Background setter is necessary so that the panel can detect mouse clicks. By default the Background is null so it ignores all mouse clicks.