adding item to context menu (programmatically)

Oct 9, 2013 at 8:48 AM
Hello folks,

I'm new to DynamicDataDisplay and also to .NET honestly.
I'm using ChartPlotter to plot a real-time variable and I need the ploting area (viewport) to be fixed by default and the line representing the variable to slide from right to left until the plot area is full and then the plot area to start translating toward left.

I succeeded in this task, but I would like that a user interacting with plot area, moving or zooming, can go back (automatically) to the initial setting, i.e. the fixed plot area sliding toward left.

The best choice for me would be add a item to the context menu, just before the others, but I don't know where to start!

I just made this try:
      MenuItem resetViewItem = new MenuItem
        Header = "Reset view",
        ToolTip = "Turn the view to last 30 seconds",
        Icon = new Image { Source = new BitmapImage(new Uri("C:\\Users\\LabSviNa\\Desktop\\icona.bmp")) },
        Command = ChartCommands.FitToView,
        CommandTarget = _plotter.plotter

but it result in a nullreferenceexeception, because the property StaticMenuItems getter return null.

I hope someone could help me.


Jul 26, 2014 at 2:25 PM
This code works
<d3:ChartPlotter Name="Chart"  HorizontalAlignment="Left" Height="270" Margin="320,145,0,0" VerticalAlignment="Top" Width="557" Background="Transparent" BorderThickness="0" FontSize="10">
                        <d3:HorizontalDateTimeAxis Name="dateAxis">
                        <d3:VerticalAxis Name="countAxis"></d3:VerticalAxis>


ObservableCollection<object> staticMenuItems = (ObservableCollection<object>)Chart.ContextMenu.ItemsSource;
 MenuItem limitMenuItem = new MenuItem
                Header = "Limit",
                IsCheckable = true

            Chart.ContextMenu.ItemsSource = staticMenuItems;