WPF - When application Loads, do not steal Focus from any another application - wpf

I have a simple WPF application. When it loads and I am typing in any other application (like Word or IM), my WPF app steals the focus - screwing up my typing, of course. Now, this is the very behavior I find annoying in other applications. How can I prevent this behavior?
Thank you.

Setting ShowActivated = false on your window prior to calling Show() should accomplish what you want.

Related

Minimize application during active ProgressDialog

Is there a way to give the user the option to minimize the application while showing the ProgressDialog?
controller = await dialogCoordinator.ShowProgressAsync(this, "Header", "Message, please wait...");
It currently remains opened and user is unable to minimize or move the window.
We've had the same requirement on our Application which lead us to develop our own ProgressBar control and place it on a layer on top of the Application, in the MainView which left the top bar including the minimize and maximize buttons - working.
The problem you are describing is general and has nothing to do with the dialog you are displaying. If mahapps.metro is really just a toolkit, standard solutions should work
Appplication.MainWindow.WindowState = WindowState.Minimized
If this still doesn't work for you, it means that you are in the "framework in the framework" situation and have to get out of the box using some win32 interop like ShowWindow(...)
Hi we also faced this issue, after lots of months of searching in google and gitter ,
I found that there is a property in the metroWindow class (which is this,in the author example)
metroWindow.ShowDialogsOverTitleBar
once I set it to false , I was able to minimize my application via the title bar ,
hopes it helps anyone.

EnableModelessKeyboardInterop or WindowInteropHelper when opening a WPF window from a Winforms app

I have a winforms application opening a wpf window. I've used both methods below:
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(window)
and
Dim helper As System.Windows.Interop.WindowInteropHelper = New System.Windows.Interop.WindowInteropHelper(window)
helper.Owner = Me.Handle
I've opted to use the second method, as the application, in random occasions, will fail to display the content of the wpf window, and even crash it. This will occur in different environments (32/64) with xp or 7, and unfortunately, I was never able to reproduce it in development. This window only uses a datagrid, with some interaction done via button controls. Anyways, by switching over to the second method, it seemed to have corrected the issue altogether. The bug has not manifested for months now. However, now I’m adding a textbox control to this window, and noticed that it’s not allowing the text entry, only spaces. If I switch back to the original method, it works, but I’m afraid the issue will start showing up in production again. Has someone come across this issue before? Any advice will be greatly appreciated!

How to implement "Please Wait" screen in Silverlight

I have developed a Silverlight application. It has a button and once it is clicked the application starts doing something which takes time. Since everything in Silverlight is asynchronous the UI is not lagging, however, I would like to add some animation to it or something else to indicate that the application is actually doing some work and that the user should wait.
I don't know how to implement this, neither thread nor XAML wise. What is the best approach to this? Thanks.
Silverlight 4 wait/spinner control
Or if you are using MVVM
Generally Preferred Method for a 'Wait' Screen using MVVM and Silverlight
You can get the busy indicator control out of the Silverlight Toolkit:
http://silverlight.codeplex.com/

Windows App Focus: Why does it require a click?

When I have 2 apps open and one has the focus but I want to execute a command in the other app, it requires a click to regain focus and another to execute the command. Is there some good reason why I couldn't take focus on MouseOver? I'm working with a WPF app if that is pertinent. TIA
EDIT: Oddly enough the MouseOvers work without focus.
I would not recommend doing this. This is not a standard way of working in Windows, so you will confuse your users. People are used to clicking into an application (or tabbing) to provide focus.
However, this is a configurable setting via the Accessability Tools in Windows. It can be enabled by choosing "Activate a window by hovering over it with the mouse" globally. Let your users specify this behavior if they want it.
The setting is configurable at a system-wide level. You should never ever override the user's current setting regarding this.
MS Windows Vista -- focus follows mouse (There's also a link on how to do it on XP.)
Edit: Normally, you can click a button on a form and both bring focus to the window and click it at the same time. The origins of the current setting "eating" the initial mouse click that brings focus to a window started as a fix to a bug in the Ribbon UI. The discussion is somewhere in this video: The Story of the Ribbon. Sorry I can't narrow it down more than that, but at least the video is a great insight and work watching - maybe you can send a message to Jensen Harris if you need a faster answer.
Edit 2: I just added a button to a WPF window, and I'm able to click it as long as I can see it - whether or not the window has focus.
You can take focus on MouseOver manually

How to run Google Earth Inside a WPF Control

I’m trying to run Google earth inside WPF but I don’t know how. Basically I have managed to run Google Earth in a Windows Form Control inside a Windows Form, everything was OK.
Trying to do the same thing in WPF, well, give strange result a small Google Earth screen placed anywhere in the form an not inside the User Control I have created, and there is now way to make this Google Earth Control grow, or shrink, when I grow or shrink the WPF Form.
Any help would be appreciated, I really mean any!
If you have a Windows Forms control that already works exactly as you want, you could always use WindowsFormsHost to put that control on your WPF form. That might be the easiest thing to do... or is that what you're already doing that isn't working?
I also wrote an application that placed Google Earth inside a WinForms WebBrowserControl that was based on the more-or-less official example hosted by Google. It worked fine. I struggled to recreate the same application inside a WPF WebBrowserControl. My experience confirms what appears to be the general consensus that the WPF WebBrowserControl is harder to use because it provides less control. (e.g. With the WinForms WebBrowserControl you can use the properties to remove the scroll bar and eliminate the IE security question on startup, but with WPF WebBrowserControl you have to use kludges inside to HTML file loaded to get the same effect.) If you are following the Google GE plugin WinForms example, you have to move the JavaScript callback functions into a separate class because of WPF window cant be a parent of the .Net-COM interop between JavaScript and C#. Maybe the other artifacts you described are due to how you resolved this latter limitation. Before finding this solution, I was tempted to put the WinForms WebBrowser control inside the WPF window, but others have posted of unpleasing side-effects of doing this.

Resources