Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
NTWindow thread ownership
Collapse
X
-
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.
-
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.
Comment
-
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
-
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;
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment