Winform Application UI Freeze while switching between other opened application - c#

I've developed Windows Application using C# and .Net Framework 4.5
My application loads user control and takes input from users. There are probably more than 100 controls on that user control. It works fine when I am actively using my system.
Problem is when I keep my application open and toggle to other applications which are also running e.g. checking my email, browse internet or using excel. After returning to my program, I can see the frame of my program and few controls but not all of them and I can see through my program to the last application which I visited. Also title bar of my app will become black.
Please note that my app doesn't become inaccessible. It's just won't load my all controls. I've assigned shortcut key to reload user control by which I can reload my user control and then it works fine.

I believe that your custom controls need some special drawing and this makes me think about the paint event.
Since you found a fix yourself
I've assigned shortcut key to reload user control
I believe that you can use the OnFocus event to call this shortcut key or the code behind it.

Related

Trying to detect and gather data on click outside application

I would like to know if it is possible to, while running a WPF window application in Visual Studio, wait for the user to click anywhere on the screen (not necessarily inside the window of my application - for the purpose of my application, the click would most likely occur inside a browser page) and then gather the information about the click (like inside the window of which application the user clicked, or the selector of the html element the user clicked)? I know this question might be very confunsing but this is basically my last resort since researching on the Internet hasn't helped me much. Just to provide a better idea of what I seek, it's like what the 'Extract Structured Data' Activity does in UiPath. Oh and I'm using C# by the way.
You can try and use this external library called GlobalMouseHook.
This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
Here is what you can do with this library:
Mouse coordinates
Mouse buttons clicked
Mouse drag actions
Mouse wheel scrolls
Key presses and releases
Special key states
Hope this helps.

How to refresh WPF AutomationElement with DataTemplate - Windows UI Automation

I am trying to automate the testing of a WPF application using Windows UI Automation.
The application has a ContentControl with a data template that changes based on user interaction.
On initial load, I am able to get and click a button inside of the content control. This switches the data template (the sub-controls are removed and replaced with other ones).
However, when I look for the new controls in the automation element, they cannot be found.
I am using the wrapper FlaUI, but I've also tried White and they both have the same sort of result.
I am not using caching, but it seems like the window is somehow cached. Is there a way to reload the element or entire window so that I can retrieve the new controls.
Found the solution on FlaUI's FAQ.
When using DevExpress controls, some things (like tab content) are not
updated By default, DevExpress controls do not raise automation
events, as these events may decrease the application performance. To
make sure that the events are raised properly, set the
ClearAutomationEventsHelper.IsEnabled static property to false on
application startup (needs to be done in the application that is
automated with FlaUI):
ClearAutomationEventsHelper.IsEnabled = false;

WPF UI Automation - Control Tree not poluated till region is clicked for a TabControl

I am doing a UI automation for a WPF application using the Microsoft UI Automation library and it works well.
However my app has four screens in a TabControl. Even when I click the tab item through code its child control tree isnt populated. The only control I can see is the "thumb" Control. Same happens when I see the control tree with UISpy.
However if the window is clicked then all the controls appear. As a Workaround I am simulating a mouseclick through code and it works. I wanted to know if there is some better way of doing it.
I ran into a problem similar to this. What was happening was some data was being retrieved on threads and the controls were not generated at the point automation peers were generated. I would suggest if you have access to the code base for the application you are attempting to automate looking into whether threading is being used. In my specific case it was because BeginInvokes were used to retrieve the data, I switched them to Invokes and it worked fine.
Also from what I could tell the reason the controls were being show on mouse over was because the tool tip generated a popup and caused the automation peers to be updated.
Why don't you click the control using mouse events if that is what works.
(Now, if you still are having that problem..)
How to simulate Mouse Click in C#?

Splash for Silverlight

I have an aspx page wherein there are different silverlight components. Each component is of different size and the xaps take different time to download.
Is there any way wherein I can be notified that all my components are downloaded?
I want to display a Splash screen till that time.
Thank You.
Maybe you can try to set an event handler to the "loaded" event of the Silverlight plugin as described here, pointing to a common function that knows each Silverlight plugin on the page and fires another event if all plugins have reported that they are loaded (to hide the splash screen).
But this requires some real-world testing to make sure that the event described there is fired if the plugin is loaded including your "payload" application (and not just the browser plugin).
Another approach could be to implement the "Loaded" event in each of the user controls that make up your applications (maybe by providing a suitable base class) and then invoke a JavaScript method in the surrounding web page as described here, setting a flag for each plugin in the page and hiding the splash screen if all plugins/applications reported to be loaded.

Events not sent to WPF based ActiveX control (COM interop) when using Reg-Free-COM

I have a WPF based ActiveX control (COM interop). I am able to use it correctly by registering the control. When I tried to Reg-Free-COM (using manifest files) the control seems to be activated, but the events (such as mouse click, RequestBringIntoView etc) dont respond. Interestingly, Double click and tab key works.
I read in the this article http://blogs.msdn.com/karstenj/archive/2006/10/09/activex-wpf-gadget.aspx that " ... These upsides come with a price: the ActiveX control must be registered in the registry, which requires some kind of installation such as an .msi. The default gadget installation process cannot install ActiveX. The ActiveX control can't be access via reg-free COM. ..."
Has anybody had a similar experience? Can anyone explain what is going on?
Additional details:
When the control is activated after it has been registered it appears as part of the COM client's UI. The control does not receive focus, its elements receive it.
When using reg-free-com the control does not load correctly.
1) The control receives focus instead of its sub elements
2) The control has areas that are black instead of the windows default color
3) when I tab in and out of the control or double click it, it's subelements receive focus, the control starts receiving events and the black areas are replaced by the correct color
I discovered that the control was inactive because the miscStatus attribute which is set on registering COM is required to activate it. I will post a separate question on that.

Categories