VNarasimhaM
VNarasimhaM

Reputation: 1570

Simple, quick way to get user input in 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?

Upvotes: 18

Views: 19131

Answers (2)

Pete OHanlon
Pete OHanlon

Reputation: 9146

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)

Upvotes: 29

Simon P Stevens
Simon P Stevens

Reputation: 27499

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.

Upvotes: 2

Related Questions