示例#1
0
        protected void CreateWPFControls()
        {
            chartWindow = System.Windows.Window.GetWindow(ChartControl.Parent) as Chart;
            chartGrid   = chartWindow.MainTabControl.Parent as System.Windows.Controls.Grid;
            chartTrader = chartWindow.FindFirst("ChartWindowChartTraderControl") as Gui.Chart.ChartTrader;

            buttonGrid = new System.Windows.Controls.Grid();

            buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition()
            {
                Height = new GridLength(50)
            });
            buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition()
            {
                Height = new GridLength(50)
            });
            buttonGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition()
            {
                Height = new GridLength(50)
            });

            System.Windows.Controls.TextBlock label = new System.Windows.Controls.TextBlock()
            {
                FontFamily          = ChartControl.Properties.LabelFont.Family,
                FontSize            = 13,
                Foreground          = ChartControl.Properties.ChartText,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(5, 5, 5, 5),
                Text   = string.Format("{0} {1} {2}", Instrument.FullName, BarsPeriod.Value, BarsPeriod.BarsPeriodType)
            };

            System.Windows.Controls.Grid.SetRow(label, 0);
            buttonGrid.Children.Add(label);

            button1 = new System.Windows.Controls.Button()
            {
                Content             = "Button 1",
                HorizontalAlignment = HorizontalAlignment.Center
            };
            button1.Click += Button1_Click;

            System.Windows.Controls.Grid.SetRow(button1, 1);
            buttonGrid.Children.Add(button1);

            button2 = new System.Windows.Controls.Button()
            {
                Content             = "Button 2",
                HorizontalAlignment = HorizontalAlignment.Center
            };
            button2.Click += Button2_Click;

            System.Windows.Controls.Grid.SetRow(button2, 2);
            buttonGrid.Children.Add(button2);

            if (TabSelected())
            {
                InsertWPFControls();
            }

            chartWindow.MainTabControl.SelectionChanged += TabChangedHandler;
        }
示例#2
0
        protected void CreateWPFControls()
        {
            chartWindow = System.Windows.Window.GetWindow(ChartControl.Parent) as NinjaTrader.Gui.Chart.Chart;
            chartGrid   = chartWindow.MainTabControl.Parent as System.Windows.Controls.Grid;
            chartTrader = chartWindow.FindFirst("ChartWindowChartTraderControl") as Gui.Chart.ChartTrader;

            //chartGrid.Background = BackBrush;

            // upper tool bar objects
            // upper tool bar menu
            topMenu = new System.Windows.Controls.Menu()
            {
                Background        = activeBackgroundDarkGray,
                BorderBrush       = controlLightGray,
                Padding           = new System.Windows.Thickness(0),
                Margin            = new System.Windows.Thickness(0),
                VerticalAlignment = VerticalAlignment.Center
            };

            Style mmiStyle = Application.Current.TryFindResource("MainMenuItem") as Style;

            topMenuItem1 = new Gui.Tools.NTMenuItem()
            {
                Background        = controlLightGray,
                Foreground        = textColor,
                Header            = "Menu 1     v",
                Margin            = new System.Windows.Thickness(0),
                Padding           = new System.Windows.Thickness(1),
                Style             = mmiStyle,
                VerticalAlignment = VerticalAlignment.Center
            };

            topMenuItem1SubItem1 = new Gui.Tools.NTMenuItem()
            {
                Background      = controlLightGray,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = textColor,
                Header          = "Submenu Item 1"
            };

            topMenuItem1SubItem1.Click += TopMenuItem1SubItem1_Click;
            topMenuItem1.Items.Add(topMenuItem1SubItem1);

            topMenuItem1SubItem2 = new Gui.Tools.NTMenuItem()
            {
                Background = controlLightGray,
                Foreground = textColor,
                Header     = "Submenu Item 2"
            };
            topMenuItem1SubItem2.Click += TopMenuItem1SubItem2_Click;
            topMenuItem1.Items.Add(topMenuItem1SubItem2);

            topMenu.Items.Add(topMenuItem1);

            // upper tool bar button, has text and image
            topMenuItem2 = new System.Windows.Controls.MenuItem()
            {
                Background = controlLightGray,
                FontSize   = 12,
                Foreground = textColor,
                Padding    = new System.Windows.Thickness(1),
                Margin     = new System.Windows.Thickness(5, 0, 5, 0)
            };

            // this stackpanel allows us to place text and a picture horizontally in topMenuItem2
            System.Windows.Controls.StackPanel topMenuItem2StackPanel = new System.Windows.Controls.StackPanel()
            {
                Orientation         = System.Windows.Controls.Orientation.Horizontal,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            System.Windows.Controls.TextBlock newTextBlock = new System.Windows.Controls.TextBlock()
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin            = new System.Windows.Thickness(0, 0, 2, 0),
                Text              = "B1 ",
                ToolTip           = "Button 1",
                VerticalAlignment = VerticalAlignment.Top
            };

            topMenuItem2StackPanel.Children.Add(newTextBlock);

            // check to see if an image exists in Documents\bin\Custom\Indicators called B1.png.
            // if its there, include this with the button
            System.Windows.Media.Imaging.BitmapImage buttonImage = new System.Windows.Media.Imaging.BitmapImage();

            try
            {
                buttonImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(NinjaTrader.Core.Globals.UserDataDir + @"bin\Custom\Indicators\B1.png"));
            }
            catch (Exception e) { }

            System.Windows.Controls.Image imageControl = new System.Windows.Controls.Image();

            if (buttonImage != null)
            {
                imageControl = new System.Windows.Controls.Image()
                {
                    Source = buttonImage,
                    Height = 10,
                    Width  = 10
                };
            }

            if (buttonImage != null)
            {
                topMenuItem2StackPanel.Children.Add(imageControl);
            }

            topMenuItem2.Header = topMenuItem2StackPanel;
            topMenuItem2.Click += TopMenuItem2_Click;
            topMenu.Items.Add(topMenuItem2);

            // bottom toolbar objects
            botMenu = new System.Windows.Controls.Menu()
            {
                Background        = activeBackgroundDarkGray,
                BorderBrush       = controlLightGray,
                Padding           = new System.Windows.Thickness(0),
                Margin            = new System.Windows.Thickness(0),
                VerticalAlignment = VerticalAlignment.Center
            };

            Style mmiStyleBot = Application.Current.TryFindResource("MainMenuItem") as Style;

            botMenuItem1 = new Gui.Tools.NTMenuItem()
            {
                Background        = controlLightGray,
                Foreground        = textColor,
                Header            = "Menu 1     v",
                Margin            = new System.Windows.Thickness(0),
                Padding           = new System.Windows.Thickness(1),
                Style             = mmiStyleBot,
                VerticalAlignment = VerticalAlignment.Center
            };

            botMenuItem1SubItem1 = new Gui.Tools.NTMenuItem()
            {
                Background      = controlLightGray,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = textColor,
                Header          = "Submenu Item 1"
            };

            botMenuItem1SubItem1.Click += BotMenuItem1SubItem1_Click;
            botMenuItem1.Items.Add(botMenuItem1SubItem1);

            botMenuItem1SubItem2 = new Gui.Tools.NTMenuItem()
            {
                Background = controlLightGray,
                Foreground = textColor,
                Header     = "Submenu Item 2"
            };
            botMenuItem1SubItem2.Click += BotMenuItem1SubItem2_Click;
            botMenuItem1.Items.Add(botMenuItem1SubItem2);

            botMenu.Items.Add(botMenuItem1);

            // upper tool bar button, has text and image
            botMenuItem2 = new System.Windows.Controls.MenuItem()
            {
                Background = controlLightGray,
                FontSize   = 12,
                Foreground = textColor,
                Padding    = new System.Windows.Thickness(1),
                Margin     = new System.Windows.Thickness(5, 0, 5, 0)
            };

            // this stackpanel allows us to place text and a picture horizontally in topMenuItem2
            System.Windows.Controls.StackPanel botMenuItem2StackPanel = new System.Windows.Controls.StackPanel()
            {
                Orientation         = System.Windows.Controls.Orientation.Horizontal,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            System.Windows.Controls.TextBlock newTextBlockBot = new System.Windows.Controls.TextBlock()
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin            = new System.Windows.Thickness(0, 0, 2, 0),
                Text              = "B1 ",
                ToolTip           = "Button 1",
                VerticalAlignment = VerticalAlignment.Top
            };

            botMenuItem2StackPanel.Children.Add(newTextBlockBot);

            // check to see if an image exists in Documents\bin\Custom\Indicators called B1.png.
            // if its there, include this with the button
            buttonImage = new System.Windows.Media.Imaging.BitmapImage();

            try
            {
                buttonImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(NinjaTrader.Core.Globals.UserDataDir + @"bin\Custom\Indicators\B1.png"));
            }
            catch (Exception e) { }

            imageControl = new System.Windows.Controls.Image();

            if (buttonImage != null)
            {
                imageControl = new System.Windows.Controls.Image()
                {
                    Source = buttonImage,
                    Height = 10,
                    Width  = 10
                };
            }

            if (buttonImage != null)
            {
                botMenuItem2StackPanel.Children.Add(imageControl);
            }

            botMenuItem2.Header = botMenuItem2StackPanel;
            botMenuItem2.Click += BotMenuItem2_Click;
            botMenu.Items.Add(botMenuItem2);

            // left toolbar objects
            // each vertical object needs its own menu
            leftInnerGrid = new System.Windows.Controls.Grid();

            leftInnerGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
            leftInnerGrid.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);

            leftInnerGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
            leftInnerGrid.RowDefinitions[1].Height = new GridLength(30);

            leftMenu1 = new System.Windows.Controls.Menu()
            {
                Background = activeBackgroundDarkGray,
                Margin     = new System.Windows.Thickness(0),
                Padding    = new System.Windows.Thickness(0)
            };

            leftMenu2 = new System.Windows.Controls.Menu()
            {
                Background = activeBackgroundDarkGray,
                Margin     = new System.Windows.Thickness(0),
                Padding    = new System.Windows.Thickness(0)
            };

            // this allows us to make our menus stack vertically
            System.Windows.Controls.VirtualizingStackPanel VerticalStackPanel = new System.Windows.Controls.VirtualizingStackPanel()
            {
                Background          = activeBackgroundDarkGray,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Orientation         = System.Windows.Controls.Orientation.Vertical,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            NinjaTrader.Gui.Tools.NTMenuItem leftMenu1Item1 = new Gui.Tools.NTMenuItem()
            {
                Background          = controlLightGray,
                Foreground          = textColor,
                Header              = "M2 v",
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Margin              = new System.Windows.Thickness(0),
                Padding             = new System.Windows.Thickness(0),                            /*,
                                                                                                   * Style				= Application.Current.TryFindResource("MainMenuItem") as Style*/
                ToolTip             = "Menu 2",
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            leftMenu1Item1SubItem1 = new Gui.Tools.NTMenuItem()
            {
                Background      = controlLightGray,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = textColor,
                Header          = "Submenu Item 1"
            };

            leftMenu1Item1SubItem1.Click += LeftMenu1Item1SubItem1_Click;
            leftMenu1Item1.Items.Add(leftMenu1Item1SubItem1);

            NinjaTrader.Gui.Tools.NTMenuItem leftMenu1Item1SubItem2 = new Gui.Tools.NTMenuItem()
            {
                Background = controlLightGray,
                Foreground = textColor,
                Header     = "Submenu Item 2"
            };

            leftMenu1Item1SubItem2.Click += LeftMenu1Item1SubItem2_Click;
            leftMenu1Item1.Items.Add(leftMenu1Item1SubItem2);

            leftMenu1.Items.Add(leftMenu1Item1);
            VerticalStackPanel.Children.Add(leftMenu1);

            leftMenu2Item1 = new System.Windows.Controls.MenuItem()
            {
                Background          = controlLightGray,
                FontSize            = 12,
                Foreground          = textColor,
                Header              = "B2",
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Margin              = new System.Windows.Thickness(0),
                Padding             = new System.Windows.Thickness(0),
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            leftMenu2Item1.Click += LeftMenu2Item1_Click;
            leftMenu2.Items.Add(leftMenu2Item1);

            VerticalStackPanel.Children.Add(leftMenu2);
            leftInnerGrid.Children.Add(VerticalStackPanel);

            // right panel
            rightInnerGrid = new System.Windows.Controls.Grid();

            rightInnerGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
            rightInnerGrid.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);

            rightInnerGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition());
            rightInnerGrid.RowDefinitions[1].Height = new GridLength(30);

            rightMenu1 = new System.Windows.Controls.Menu()
            {
                Background = activeBackgroundDarkGray,
                Margin     = new System.Windows.Thickness(0),
                Padding    = new System.Windows.Thickness(0)
            };

            rightMenu2 = new System.Windows.Controls.Menu()
            {
                Background = activeBackgroundDarkGray,
                Margin     = new System.Windows.Thickness(0),
                Padding    = new System.Windows.Thickness(0)
            };

            // this allows us to make our menus stack vertically
            System.Windows.Controls.VirtualizingStackPanel VerticalStackPanelRight = new System.Windows.Controls.VirtualizingStackPanel()
            {
                Background          = activeBackgroundDarkGray,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Orientation         = System.Windows.Controls.Orientation.Vertical,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            NinjaTrader.Gui.Tools.NTMenuItem rightMenu1Item1 = new Gui.Tools.NTMenuItem()
            {
                Background          = controlLightGray,
                Foreground          = textColor,
                Header              = "M2 v",
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Margin              = new System.Windows.Thickness(0),
                Padding             = new System.Windows.Thickness(0),                            /*,
                                                                                                   * Style				= Application.Current.TryFindResource("MainMenuItem") as Style*/
                ToolTip             = "Menu 2",
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            rightMenu1Item1SubItem1 = new Gui.Tools.NTMenuItem()
            {
                Background      = controlLightGray,
                BorderThickness = new System.Windows.Thickness(0),
                Foreground      = textColor,
                Header          = "Submenu Item 1"
            };

            rightMenu1Item1SubItem1.Click += RightMenu1Item1SubItem1_Click;
            rightMenu1Item1.Items.Add(rightMenu1Item1SubItem1);

            NinjaTrader.Gui.Tools.NTMenuItem rightMenu1Item1SubItem2 = new Gui.Tools.NTMenuItem()
            {
                Background = controlLightGray,
                Foreground = textColor,
                Header     = "Submenu Item 2"
            };

            rightMenu1Item1SubItem2.Click += RightMenu1Item1SubItem2_Click;
            rightMenu1Item1.Items.Add(rightMenu1Item1SubItem2);

            rightMenu1.Items.Add(rightMenu1Item1);
            VerticalStackPanelRight.Children.Add(rightMenu1);

            rightMenu2Item1 = new System.Windows.Controls.MenuItem()
            {
                Background          = controlLightGray,
                FontSize            = 12,
                Foreground          = textColor,
                Header              = "B2",
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Margin              = new System.Windows.Thickness(0),
                Padding             = new System.Windows.Thickness(0),
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            rightMenu2Item1.Click += RightMenu2Item1_Click;
            rightMenu2.Items.Add(rightMenu2Item1);

            VerticalStackPanelRight.Children.Add(rightMenu2);
            rightInnerGrid.Children.Add(VerticalStackPanelRight);

            if (TabSelected())
            {
                InsertWPFControls();
            }

            chartWindow.MainTabControl.SelectionChanged += TabChangedHandler;
        }