Text input in message dialog? ContentDialog?

后端 未结 3 2036
说谎
说谎 2021-02-13 19:17

I am wondering what is the best way to allow a user to input text into a MessageDialog in a Windows 10 universal app.(Forgot password system). From the research I\'ve done this

3条回答
  •  粉色の甜心
    2021-02-13 19:57

    I use such function to request text from user:

    private async Task InputTextDialogAsync(string title)
    {
        TextBox inputTextBox = new TextBox();
        inputTextBox.AcceptsReturn = false;
        inputTextBox.Height = 32;
        ContentDialog dialog = new ContentDialog();
        dialog.Content = inputTextBox;
        dialog.Title = title;
        dialog.IsSecondaryButtonEnabled = true;
        dialog.PrimaryButtonText = "Ok";
        dialog.SecondaryButtonText = "Cancel";
        if (await dialog.ShowAsync() == ContentDialogResult.Primary)
            return inputTextBox.Text;
        else
            return "";
    }
    

    and its usage:

    string text = await InputTextDialogAsync("Title");
    

提交回复
热议问题