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

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:	153
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 Mizzouman1, Today, 07:35 AM
        4 responses
        18 views
        0 likes
        Last Post Mizzouman1  
        Started by philmg, Today, 01:17 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by cre8able, Today, 01:01 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by manitshah915, Today, 12:59 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by ursavent, Today, 12:54 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X