Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NTWindow thread ownership

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    This is only a sample to debug. In the real scenario I'm opening it only when certain conditions are met. Whether I replace the contents of existing windows doesn't solve the problem where two or more processes, thread or alike want to open a window at the same time. This can happen very easily e.g. if the indicator is added to different charts or other windows, which use the same data series.

    Comment


      #17
      Hello Human#102,

      In that situation it would still be the same anwer, your script should only open the window once. You could do that initially from OnStateChange DataLoaded and then hide the window until it is needed. Another item would be to not use xaml and just build the UI by using code instead, that would help to avoid multiple scripts trying to access the file at once.

      JesseNinjaTrader Customer Service

      Comment


        #18
        I think it does make the most sense to do this in code. I'm familiar with extending existing grids and creating custom elements, but how do I create it from scratch and add make this the content of the window?

        This is my current code to create the grid, but simply assigning the grid to the `Content` doesn't work. I've read the documentation on this topic but either couldn't find an example, or it doesn't exist, how to create a custom grid for a custom AddOn window.

        Code:
        private void OnWindow_Loaded(object sender, RoutedEventArgs e)
                {
                    grid = new Grid();
                    
                    ColumnDefinition col1 = new ColumnDefinition();
                    col1.Width = new GridLength(15);
                    
                    ColumnDefinition col2 = new ColumnDefinition();
                    
                    ColumnDefinition col3 = new ColumnDefinition();
                    col3.Width = new GridLength(15);
                    
                    grid.ColumnDefinitions.Add(col1);
                    grid.ColumnDefinitions.Add(col2);
                    grid.ColumnDefinitions.Add(col3);
                    
                    grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(80) });
                    grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    
                    messageBlock = new TextBlock()
                    {
                        FontSize            = 12,
                        Foreground            = TextColor,
                        HorizontalAlignment    = HorizontalAlignment.Left,
                        VerticalAlignment    = VerticalAlignment.Center,
                        Margin                = new Thickness(0, 0, 0, 0),
                        Text                = message
                    };
                    
                    okButton = new Button()
                    {
                        Content                = "Ok",
                        Width                = 50,
                        Margin                = new Thickness(0,0,0,0),
                        Padding                = new Thickness(0,0,0,0),
                        Foreground            = TextColor,
                        VerticalAlignment     = VerticalAlignment.Bottom,
                        HorizontalAlignment = HorizontalAlignment.Left
                    };
                    okButton.Click += OnOkButton_Click;
                    
                    Grid.SetColumn(messageBlock, 1);
                    Grid.SetColumn(okButton, 1);
                    
                    Grid.SetRow(messageBlock, 0);
                    Grid.SetRow(okButton, 1);
                    
                    Content = grid;
                }​

        Comment


          #19
          Hello Human#102,

          You would need to assign the Page as the content and then add your grid to the page. You also need to add the controls to your grid as children. The basic structure would be like the following:

          Code:
          Page page = new Page();
          Grid grid = new Grid();
          
          
          ////  your existing code
          
          
          
          grid.Children.Add(messageBlock);
          grid.Children.Add(okButton);
          
          
          
          ////  your existing code
          
          
          
          page.Content = grid;
          
          
          
          
          messageBlock = LogicalTreeHelper.FindLogicalNode(page, "MessageBlock") as TextBlock;
          if (messageBlock != null)
          {
          messageBlock.Text = message;
          messageBlock.Foreground = TextColor;
          }
          
          okButton = LogicalTreeHelper.FindLogicalNode(page, "OkButton") as Button;
          if (okButton != null)
          okButton.Click += OnOkButton_Click;
          
          DependencyObject pageContent = page.Content as DependencyObject;
          
          return pageContent;​
          JesseNinjaTrader Customer Service

          Comment


            #20
            Thank you for the support, for now it seems to finally work without issues.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            16 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            4 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,785 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,407 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X