I am new to c# wpf and I want to get user input to enter their name using a popup. How to do that?
Loading
I am new to c# wpf and I want to get user input to enter their name using a popup. How to do that?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Cr BhargaviPosted Aug 28, 2023, 1:22 PM
Create a new WPF Window in your project. You can name it something like "NameInputDialog.xaml".
Design the window with a TextBox for the user to input their name and a couple of buttons (e.g., "OK" and "Cancel").
In the code-behind of the window ("NameInputDialog.xaml.cs")
Mohammad HussainPosted Aug 28, 2023, 9:00 AM
Tahir AnsariPosted Aug 27, 2023, 6:25 AM
Create a new WPF Window in your project. You can name it something like "NameInputDialog.xaml".
Design the window with a TextBox for the user to input their name and a couple of buttons (e.g., "OK" and "Cancel").
In the code-behind of the window ("NameInputDialog.xaml.cs"), create a property to store the user's input name:
When you want to show the input dialog to the user, create an instance of the custom window and display it modally:
Using MessageBox for Simplicity:
You can use the MessageBox class to get a simple input from the user, but this approach doesn't allow as much customization as a custom window.