在WPF中获得用户输入的简单快捷方法? [英] Simple, quick way to get user input in WPF?
问题描述
我最近开始为其中一个项目使用C#和WPF.
I recently started using C# and WPF for one of my projects.
有没有一种快速的方法来从用户那里获取输入?我无法为WPF项目找到一个.
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,这可能是赢奖形式.您仅需一行代码即可获得用户输入.我也可以在WPF中做到吗?
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?
推荐答案
如果将Microsoft.VisualBasic dll添加到应用程序中,则可以使用InputBox方法从用户那里获取单个值.
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);
(将-1,-1输入XPos,YPos使其位于屏幕中央)
(Put -1,-1 in for the XPos,YPos to get it centred on the screen)
这篇关于在WPF中获得用户输入的简单快捷方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!