I have a WPF application with two text box controls on a splash screen.
Now I need to set some text in this textboxes. Normally I would find control window with FindWindowEx
and call SetWindowText
, but the problem is that I can't see any windows here.
Even when I open Spy++
the only window I see is the window itself. No children at all.
Could you please explain what's going on? Does it work somewhere else in WPF? Isn't it just a normal window with normal HWND
handle? How can I set text in those controls?
I tried Snoop
as suggested in comments and I was able to see some of the windows, but not the controls on a splash screen. Also I would like to do this automatically from C# application, not manually with Snoop
. I've got the sources of Snoop
and looks like you need to ijnect something into your application in order to do this. Is it right?
Is it really that hard to set text for the WPF control from another process?
Solution is to use Microsoft UI Automation
AutomationElement rootElement = AutomationElement.RootElement;
if (rootElement != null)
{
Condition condition =
new PropertyCondition(AutomationElement.NameProperty, "WindowSplash");
AutomationElement appElement =
rootElement.FindFirst(TreeScope.Children, condition);
if (appElement != null)
{
Condition condition =
new PropertyCondition(
AutomationElement.AutomationIdProperty, "element1");
AutomationElement element =
parentElement.FindFirst(TreeScope.Descendants, condition);
if (element != null)
{
ValuePattern valuePatternB =
element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
valuePatternB.SetValue("hello automation world!");
}
}
}