从文本框中输入 [英] Taking input from text box
问题描述
嗨!
我是wpf的新手.请在这方面帮助我.
在MFC中,我们使用Update(True)或Update(False)更新控件(例如文本框).我们如何使用WPF?
我取两个名为firstTextBox和secondTextBox的文本框.现在我希望用户从键盘上的两个文本框中输入两个整数,然后单击按钮(例如AddButton),我的应用程序将它们添加并在第三个文本框中显示结果,即thirdTextBox(三个文本框和一个按钮是在名为myCanvas的画布上拍摄的. WPF中的代码是什么?
问候
Hi!
I am newcomer in wpf. Plz help me in this regard.
In MFC we updates controls(e.g textbox)with Update(True) or Update(False). How we do in WPF?
I take two textbox with name firstTextBox and secondTextBox.Now i want that user inputs two integer from keyboard in two textboxes and on clicking of a button (say AddButton) my application add them and display the result in third textbox i.e, thirdTextBox (Three textboxes and one button were taken on a canvas with name myCanvas). What will be the code in WPF?
regards
推荐答案
这个问题与Update
无关.使用.NET控件(不仅适用于WPF,甚至不仅适用于UI),您都不需要任何特殊的更新,因为所有必需的控件表示无效都通过它们的属性执行.更改属性值后,属性设置器的代码将调用属性分配所需的副作用.
如果是System.Windows.Controls.TextBox
,则通过为其属性string Text
分配一个值来更新(尤其是).
请参阅: http://msdn.microsoft.com/en-us/library /system.windows.controls.textbox.aspx [
This question has nothing to do withUpdate
. With .NET controls (not only for WPF, and not even only for UI), you don''t need any special updating, because all required invalidation of the presentation of the controls are performed through their properties. When a property value is changed, the code of the property setter invokes required side effect of property assignment.
In case ofSystem.Windows.Controls.TextBox
, it is updated by assignment a value to its propertystring Text
(in particular).
Please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx[^].
This property is all you need to solve the problem. Also, as the property is of thestring
type, and you need to work withint
, you will need to parse a string to an integer value and present the integer value as a string, so you will need to useint.Parse
(throws exception in case of invalid numeric format) orint.TryParse
(returns Boolean value depending on success) andint.ToString
.
Now, that''s really all you need.
—SA
这篇关于从文本框中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!