Reputation: 7682
I am working on an automated testing framework in WPF. I am finding that while it is possible to automate most things using the basic WPF automation framework, it is very difficult to get down to the fine grained details of what is happening at the UI level. I need to be able to see things like the properties of the DataContext, properties of controls, and so on. I know this is possible because Snoop can do it. Snoop allows you to traverse the entire Visual Tree of any WPF app. I need this functionality. So, I wrote this code:
public async Visual GetAppRootVisual()
{
var allProcesses = Process.GetProcesses();
var filteredProcess = allProcesses.Where(p => p.ProcessName.Contains(ProcessSearchText)).First();
var windowHandle = filteredProcess.MainWindowHandle;
var hwndSource = HwndSource.FromHwnd(windowHandle);
return hwndSource.RootVisual;
}
The code works up until the second last line. The second last line returns null, but I can't figure out why. The windowHandle is returned, but the HwndSource is not returned. What is going wrong here?
Upvotes: 0
Views: 79