簡體   English   中英

彈出一個帶有返回值的消息對話框

[英]popup a message dialog with return value

我是 c# 和 uwp 的新手

我彈出消息對話框的代碼是

    private void messageBoxClick(IUICommand command)
    {
        // Display message showing the label of the command that was invoked
        //rootPage.NotifyUser("The '" + command.Label + "' command has been selected.", NotifyType.StatusMessage);
    }

    public async Task messageBoxShow(string s, string commandString1, string commandString2)
    {
        var dialog = new Windows.UI.Popups.MessageDialog(s);
        dialog.Commands.Add(new UICommand(commandString1, new UICommandInvokedHandler(this.messageBoxClick)));
        dialog.Commands.Add(new UICommand(commandString2, new UICommandInvokedHandler(this.messageBoxClick)));

        await dialog.ShowAsync();


    }

有用! 但我希望得到的風格是

    string s = messageBoxShow(s, commandString1, commandString2);

以前的樣式可以改成這個樣式嗎

歡迎您的評論

MessageDialog的顯示是一個異步操作, ShowAsync返回的結果是IUICommand 如果你想獲取的字符串值是IUICommand.Label ,你可以這樣寫:

public async Task<string> messageBoxShow(string s, string commandString1, string commandString2)
{
    var dialog = new MessageDialog(s);
    dialog.Commands.Add(new UICommand(commandString1, new UICommandInvokedHandler(this.messageBoxClick)));
    dialog.Commands.Add(new UICommand(commandString2, new UICommandInvokedHandler(this.messageBoxClick)));
    var result = await dialog.ShowAsync();
    return result.Label;
}

用法

string label = await messageBoxShow(s, commandString1, commandString2);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM