Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create own MessageBoxWindow with MessageBoxResult

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

    Create own MessageBoxWindow with MessageBoxResult

    Hi, I have a problem with my own message box. I don't know exactly how to implement the "MessageBoxResult" to make it work properly. Maybe someone can help me.
    This is what the message box looks like:

    Click image for larger version

Name:	NinjaTrader_fi8Ut9MwZF.jpg
Views:	279
Size:	4.5 KB
ID:	1218755

    I hereby call the messagebox
    Code:
    var result = MessageBoxTest.Show(ChartControl, "Text");
    await result;
    
    Print("1=>" + result.Result);
    I don't know how to implement this correctly in the. Show method so that I get the feedback when the "Ok" button was pressed. After the "Ok" button is pressed, for example, a next method with other functions should be executed, but only after the "Ok" button was pressed and not already when the window was opened.

    Code:
        public static async Task<MessageBoxResult> Show(ChartControl chartControl, string text, MessageBoxButton buttons = MessageBoxButton.OK)
            {
                if (chartControl == null)
                {
                    return MessageBoxResult.None;
                }
    
                MessageBoxWindowTest msgBox = null;
                System.Windows.Threading.DispatcherOperation msgResult = null;
    
                msgResult = chartControl.Dispatcher.InvokeAsync(() =>
                {
                    msgBox = CreateMessageBox(chartControl, text, buttons);
                    if (msgBox != null)
                    {
                        msgBox.Show();
                        return msgBox.MsgBoxResult;
                    }
    
                    return MessageBoxResult.None;
                });
    
                await msgResult;
    
                return msgBox.MsgBoxResult;
            }
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    The call and return of the message box would be synchronous. Meaning within the same block of the InvokeAsync action, trigger whatever actions you are going to trigger with the message box result.

    Below is a link to a forum post with tips.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB, thank you for your reply. Unfortunately, with this variant, the chart is locked. Is there no alternative where a message box is displayed while the chart is not locked, waiting for the message "MessageBoxResult"? I would like to call only .Show() instead of .ShowDialog(), because with .Show() the chart is not locked. Unfortunately, the "MessageBoxResult" do not arrive there.
      Last edited by sidlercom80; 10-10-2022, 09:27 AM.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        The MessageBox is intended to be a modal window (meaning the chart or calling window is locked) and is intended to be code blocking until the OK or Cancel is clicked.

        If you want a window that is not modal, you can open an actual window.

        For example:



        The result of the message box can be called directly under the show which is synchronous, but not outside of the invoke action.
        Chelsea B.NinjaTrader Customer Service

        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 Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X