Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple, quick way to get user input in WPF?

Tags:

c#

wpf

I recently started using C# and WPF for one of my projects.

Is there a quick way of getting an input from the user? I have not been able to find one for WPF projects.

I don't want have to create another window, add OK and Cancel buttons, and add event handlers for everything. I can do it, but I wanted to know a simpler way of doing it.

AFAIK, that was possible in win forms. You can get user input with just one single line of code. Can I do it in WPF as well?

like image 526
VNarasimhaM Avatar asked Sep 21 '09 15:09

VNarasimhaM


2 Answers

If you add the Microsoft.VisualBasic dll to your application, you can use the InputBox method to get a single value from the user.

Microsoft.VisualBasic.Interaction.InputBox("Prompt here", 
                                           "Title here", 
                                           "Default data", 
                                           -1,-1);

(Put -1,-1 in for the XPos,YPos to get it centred on the screen)

like image 70
Pete OHanlon Avatar answered Oct 20 '22 16:10

Pete OHanlon


If your talking about basic yes/no input then there is a wpf MessageBox that works in pretty much the same way as the winforms one - see System.Windows.MessageBox

Is that what you are thinking of?

Also, all winforms classes can still be used in WPF apps, you just need to add a reference to the appropriate assembly.

like image 2
Simon P Stevens Avatar answered Oct 20 '22 17:10

Simon P Stevens