I have a multiple windows in an application, for instance, window1, window2 and window3.
one RoutedCommand (with KeyGesture F11) was binded in window1.
How to launch that routed command by pressing F11, while window2 had input focus ?
In WinForm application, i use MessageFilter to detect F11, but in WPF, how to do that ?
You can use CommandManager.RegisterClassCommandBinding to hook up a handler to every Window application wide. This will be continue working for the rest of your application run so it usually makes sense to put it in App.xaml.cs but you could put it anywhere.
CommandManager.RegisterClassCommandBinding(typeof(Window), new CommandBinding(ApplicationCommands.Cut, CutExecuted));
Related
I would like to create a WPF dialog where the user has to press (at least) two buttons before a command is executed.
I am able to create this using code-behind (touch events), but prefer to use MVVM command binding and a dedicated user control so it can be reused in other applications.
How can I activate the ICommand when both buttons are pressed simultaneously?
I have started a new project using WPF and Catel and I want to be able to have multiple windows without ownership. I have been able to create an application with a standard window and which creates dialogs. I would like to find an example or tutorial on how to create a window and then close the current window.
Example:
Window1 -> Select Open Window2 Button -> Open Window2 -> Close Window1
Thanks
When you call Show on the UIVisualizer, it should show the window non-modal. After calling the UIVisualizer service, just call CloseViewModel on yourself and the current window should close.
It appears that the above answer is correct as long as you are not closing the startup window.
It appears that when you close the ViewModel that is targeted as your startup View\ViewModel when you close it, it closes the whole application.
My question now.. How can I prevent this from happening.
In Winforms you just have the Main function and that's what runs first, but in WPF you set the window you want to start with in the Application.xaml file. If I try to run anything other than a window, how would I do that? I'm porting over a winforms application that does some logic at start to determine which window to open and I'd rather have it just be a class that runs than a window that never appears.
Remove the StartupUri from App.xaml, override OnStartup in App.xaml.cs.
I am using a third-party Windows Forms control that performs some actions "delayed" using the Application.Idle event.
Now that we're moving our application to WPF, these actions stopped working.
I've found that the System.Windows.Forms.Application.Idle event is not raised as expected.
How can I get the Idle event to fire in a WPF application so that I can continue to use that third-party control (within a WindowsFormsHost)? It is not possible to modify the Windows Forms control.
You should read this page on MSDN which describes the message loop behavior in a WPF application. In particular it looks like the ComponentDispatcher class can be used to catch a ThreadIdle event which would roughly correspond to the Windows Forms Application.Idle event.
You could then presumably use the System.Windows.Forms.Application.RaiseIdle method to raise the Idle event as the component expects.
If you are using a WPF Application, you are actually no longer using the System.Windows.Forms.Application class to run your application, even if your application contains a Windows Forms Control.
Instead, you are using the System.Windows.Application class (different namespace).
We had a big project developed in WinForm. Now I'm adding a new window to the project using WPF. The WPF window is now part of the project, i.e. it is not a seperate project or dll. What happened now is any control that is supposed to accept key inputs, such as textbox, does not respond to my keyboard input. The window only responds to mouse.
If I create another WPF project and call this window, all keys work!
Does anyone know the reason for this? Any work around? Thanks!
When creating your WPF window from your Winforms code, be sure to use ElementHost.EnableModelessKeyboardInterop to allow WPF input to work.
Example:
Window window = new Window1();
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();