How to pop up a modal UWP dialog that allows the user to provide a string input

Private Coder 75 Reputation points
2023-04-03T18:35:41.5366667+00:00

I have a UWP UI to which I need to add a modal pop-up that allows the user to provide a string input. How would I do that? I have found widgets like Windows.Security.Credentials.UI. CredentialPicker but nothing for plain strings.

Universal Windows Platform (UWP)
{count} vote

Accepted answer
  1. Roy Li - MSFT 33,491 Reputation points Microsoft Vendor
    2023-04-04T08:24:56.5066667+00:00

    Hello, Welcome to Microsoft Q&A!

    There is no built-in control like that. You might need to create a "string picker" using ContentDialog by yourself. What you just need to put a TextBox inside the ContentDialog to get user input. I've made a simple one and you could refer to it: Xaml:

       <ContentDialog x:Name="termsOfUseContentDialog"
                           Title="Title"
                           PrimaryButtonText="OK"
                           PrimaryButtonClick="termsOfUseContentDialog_PrimaryButtonClick"
                           CloseButtonText="Cancel">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="This is meesage" Grid.Row="0" Margin="5"/>
                    <TextBox x:Name="InputBox" Width="350" Height="32" Grid.Row="1" Margin="5" PlaceholderText="URL"/>
                </Grid>
            </ContentDialog>
    

    Code-behind:

     public MainPage()
    {
        this.InitializeComponent();
        this.Loaded += MainPage_Loaded;
    }
    
    private async void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        await termsOfUseContentDialog.ShowAsync();
    }
    
    private void termsOfUseContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {
        var inputstring = InputBox.Text;
    }
    
    

    How it looks like: User's image

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.