Setting Value in WPF Textbox

Setting Value in WPF Textbox

As a continuation to the previous WPF automation article. In this topic, we will see how to set value in WPF Textbox.
Let’s see how it can be implemented using System.Windows.Automation.ValuePattern class.
To explain this implementation, we have used the below application to set the value in Textbox.

Code


Now to set the value in the WPF Textbox, We need to get the window handle for the WPF Application and then call the above function. We pass three arguments to the function: 1.Window Handle 2.Index of the Textbox : Since ‘Email’ is the first textbox available in the window, we pass the index argument value as 1 3.Value to be set in the textbox. Eg. “xxx@yyy.com”

Synopsis

Once the above code is run, the value specified will be set in the textbox. In the above function, the textbox is identified in the Window with the help of ControlTypeProperty.

Leave a Reply

Your email address will not be published. Required fields are marked *