We are developing a WPF 4.0 application for internal use.
On some clients, we are experiencing huge performance issues due to UI automation
(these clients have software installed like tablet service pen, touch, ..).
This is a known issue for WPF 4.0, see for instance:
We've been able to reproduce this issue on a machine with very limited specs.
Opening a WPF window on this machine takes:
As you can see, installing hotfix KB2484841 is a huge improvement, but still not as fast as running without ui Automation triggering software installed.
Furthermore, we do not have much control over which software to install at the clients, so it's hard to roll out this fix for all clients.
Therefore, is it possible to "turn off" UI Automation for an entire WPF application? I know it can be done on a per-UserControl basis, but is it possible for the app as a whole?
I've tried the code provided in this post, but without success.
Thanks for your time,
Koen
We hit the exact same issue mentioned in the question, where a UI automation client was impacting the performance of our WPF
application.
After trying all the hot fixes and workarounds, finally we found a solution. Each UI control has an AutomationPeer
object that exposes the properties of the current control and its child controls. The UI automation client uses these AutomationPeer
objects to get the information about the UI controls. There are built-in automation peer class for most of the UI controls in WPF
and we can also create a custom peer class.
The following is a custom automation peer class. Note that in the GetChildrenCore
method, it is returning an empty list instead of the list of actual child controls.
public class CustomWindowAutomationPeer : FrameworkElementAutomationPeer
{
public CustomWindowAutomationPeer(FrameworkElement owner) : base(owner) { }
protected override string GetNameCore()
{
return "CustomWindowAutomationPeer";
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Window;
}
protected override List<AutomationPeer> GetChildrenCore()
{
return new List<AutomationPeer>();
}
}
Then in your main window, override the OnCreateAutomationPeer
method:
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new CustomWindowAutomationPeer(this);
}
Now when the UI automation client tries to get the child controls of the main window, it gets back an empty list and so it cannot iterate through the rest of the controls.
Refer this MSDN article for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With