This project is read-only.

Changing Context menu depending on what is clicked?

Jul 9, 2009 at 11:53 AM

Is to possible to customise the context menu for each control in the plot?

What I am asking is, is it possible for example if I right click on the Vertical Axis to show Vertical Axis specific menu items? I have looked through the DDD code and can see the following which handles the mouse event. The hitResults is correctly returning the contents say of the Axis Title. What would I like to have is the possible to rename the axis title by right/double clicking on the title. Is this possible or can you even point me in the correct direction?

I can correctly bind new items to the context menu, however I would prefer if these were object specifc (i.e. right click on axis, right click on title)

 

		private void plotter_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
		{
			Point position = e.GetPosition(plotter);
			if (mousePos == position)
			{
				hitResults.Clear();
				VisualTreeHelper.HitTest(plotter, null, CollectAllVisuals_Callback, new PointHitTestParameters(position));

				dynamicMenuItems.Clear();
				var dynamicItems = hitResults.Where(r =>
				{
					var items = GetPlotterContextMenu(r);
					return items != null && items.Count > 0;
				}).SelectMany(r => GetPlotterContextMenu(r));

				foreach (var item in dynamicItems)
				{
					dynamicMenuItems.Add(item);
				}

				staticMenuItems.AddMany(dynamicMenuItems);

				plotter.Focus();

				plotter.ContextMenu.IsOpen = true;
				e.Handled = true;
			}
		}

 

Jul 13, 2009 at 8:01 AM

Hi,

 

There is a possibility to add custom context menu items situated after default static menu items. This can be done by setting a value to special attached dependency property DefaultContextMenu.PlotterContextMenu.

Value of this property should be special ObjectCollection, filled by you own MenuItems.

I've uploaded a sample for you - http://cid-eaf0a921258b5980.skydrive.live.com/self.aspx/.Public/D3/ContextMenuSample.zip - try to click on rectangle and check 'Change color' in context menu.

 

If you need extra functionality, please post your suggestions here.

Best regards,

Mikhail.

Mar 26, 2010 at 10:45 AM

Hi,

How can i add a new menu item to the default plotter in general and not over a rectangle region, the below code doesn't seem to work. Thanks much.

<Grid>
        <d3:ChartPlotter Name="plotter">
                    <d3:DefaultContextMenu.PlotterContextMenu>
                        <d3:ObjectCollection>
                            <MenuItem Header="Change Color" Click="MenuItem_Click"/>
                        </d3:ObjectCollection>
                    </d3:DefaultContextMenu.PlotterContextMenu>
            <d3:AxisCursorGraph/>
        </d3:ChartPlotter>
    </Grid>

Oct 21, 2010 at 4:10 PM
rohits79 wrote:

Hi,

How can i add a new menu item to the default plotter in general and not over a rectangle region, the below code doesn't seem to work. Thanks much.

<Grid>
        <d3:ChartPlotter Name="plotter">
                    <d3:DefaultContextMenu.PlotterContextMenu>
                        <d3:ObjectCollection>
                            <MenuItem Header="Change Color" Click="MenuItem_Click"/>
                        </d3:ObjectCollection>
                    </d3:DefaultContextMenu.PlotterContextMenu>
            <d3:AxisCursorGraph/>
        </d3:ChartPlotter>
    </Grid>

Mikhail,

I need the same thing. Please provide us a way to declare the PlotterContextMenu one level inside the ChartPlotter instead of having to put it inside some other arbitrary element.

Regards,
Forrest

Nov 7, 2010 at 9:18 AM

Hi!

My name is Mikhail Brinchuk, and I am a developer of DynamicDataDisplay.

I'm searching now a remote job, so if you or your company can offer it to me, I will be very grateful.

If you want to customize DynamicDataDisplay somehow, I can help you to do it.

My CV is here - https://sites.google.com/site/thecentury/

Best regards,

Mikhail.

Feb 15, 2012 at 9:06 PM

I just figured this out. I thought I'd share it with the community and document an answer to both rohits79 and alt_tab.

Try this xaml inside your plotter:

 

         <d:ChartPlotter Name="CumMonthPlot" Grid.Row="0" Background="{x:Null}" Margin="0,45,5,10">

            <d:AxisCursorGraph/>
            
            <d:ViewportPanel Name="ViewPanel" Background="WhiteSmoke">
               <d:DefaultContextMenu.PlotterContextMenu>
                  <d:ObjectCollection>
                     <MenuItem Header="Change Color" Click="MenuItem_Click"/>
                  </d:ObjectCollection>
               </d:DefaultContextMenu.PlotterContextMenu>
            </d:ViewportPanel>
</d:ChartPlotter>