Products Technologies Demo Docs Blog Support Company

Sneak Peek X15: UI Automation Interface for TX Text Control .NET for WPF

UI automation is a programmatic interface to external applications that needs programmatic access to the application. TX Text Control provides a very powerful API to developers who integrate the libraries into their applications. But this interface is not open to other applications from outside the application. Primarily, UI automation is used for the Windows accessibility features such as screen readers and third-party applications like speech recognition software packages. The UI…

Sneak Peek X15: UI Automation Interface for TX Text Control .NET for WPF

UI automation is a programmatic interface to external applications that needs programmatic access to the application. TX Text Control provides a very powerful API to developers who integrate the libraries into their applications. But this interface is not open to other applications from outside the application. Primarily, UI automation is used for the Windows accessibility features such as screen readers and third-party applications like speech recognition software packages.

The UI automation framework provides a streamlined way to discover UI components in an application. With version X15 of TX Text Control .NET for WPF, the UI automation framework interface is implemented and provides the following advantages:

  • Enabled accessibility features
    Accessibility is getting more important and applications must be compliant with government regulations.
  • Automated UI testing
    Applications that support the UI automation interface can be tested automatically. This can be very helpful for costly and time consuming regression testing.

UI automation provides a common interface to communicate with applications that implement this interface. The automation object is provided using the System.Windows.Automation.AutomationElement class connected with an UIElement. There are several control patterns that expose functionality which can be used from outside.

TX Text Control supports 3 patterns:

  • ValuePattern
    Represents a control that has an intrinsic value that does not span a range and can be represented as a string. This string may or may not be editable depending on the control and its settings.
  • TextPattern
    Represents controls that contain text.
  • SynchronizedInputPattern
    Represents objects that support synchronized input events.

How to Use the UI Automation Interface?

The following method starts an external application and returns the parent AutomationElement:

private AutomationElement StartApp(string app)
{
    p = Process.Start(app);
    Thread.Sleep(2000);
    return (AutomationElement.FromHandle(p.MainWindowHandle));
}

This method returns the first AutomationElement in the UI tree that supports the TextPattern (TX Text Control in this case):

private AutomationElement GetTextElement(AutomationElement targetApp)
{
  PropertyCondition cond =
      new PropertyCondition(
      AutomationElement.IsTextPatternAvailableProperty,
      true);

  AutomationElement targetTextElement =
      targetApp.FindFirst(TreeScope.Descendants, cond);

  return targetTextElement;
}

The following code snippet uses the above methods to start a test application and to retrieve the TX Text Control AutomationElement. If the element supports the ValuePattern, a text is set.

// start the application 
AutomationElement element = StartApp("tx_wpf_client.exe");

// get TX Text Control
AutomationElement textElement = GetTextElement(element);

object valuePattern = null;

if (textElement.TryGetCurrentPattern(
        ValuePattern.Pattern, out valuePattern))
{
    ((ValuePattern)valuePattern).SetValue("This is text");
}

The next code snippet selects the complete text in a DocumentRange:

if (textElement.TryGetCurrentPattern(
        TextPattern.Pattern, out textPattern))
{
    TextPatternRange currentSelection = ((TextPattern)textPattern).DocumentRange;
    currentSelection.Select();
}

Stay tuned for more features of TX Text Control X15.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

WPF

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your WPF application. TX Text Control .NET for WPF is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See WPF products

Related Posts

ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ActiveXASP.NETWindows Forms

Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5

TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…


ASP.NETWindows FormsWPF

The Wait is Over: TX Text Control for Linux is Officially Here

We are very excited to announce the release of TX Text Control 33.0 which includes the long awaited Linux version of TX Text Control. This version allows you to integrate TX Text Control into your…


ASP.NETWindows FormsWPF

Full .NET 9 Support in Text Control .NET Components for ASP.NET Core,…

.NET 9 will be launched tomorrow, November 12, at the .NET Conf 2024 with updates to cloud capabilities, security, and performance. TX Text Control .NET components are fully compatible with .NET 9…