Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
ContextMenu on Axis
posted

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

Parents
No Data
Reply
  • 34510
    Verified Answer
    Offline posted

    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.

Children