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.
Related
I have a WPF application with a MainWindow and a couple of Dialogs that appear over MainWindow.
I want my main window to be activated and appear on top of all dialogs when its clicked. I have tried method Activate() but its not working ,also tried Topmost which is also not working ?
Please suggest a solution.
I suppose you are using ShowDialog() to open the other dialogs. Try using Show() when opening new dialogs as that won't force you to close them before being able to access the MainWindow. Of course without a bit more information on your code it's impossible to know exactly what causes the problem.
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 a Silverlight application that doesn't run in a browser, is it possible to create a new top-level window? Or at least a child window?
I found some solution using the ChildWindow class, but even though my project is configured for Silverlight 4, that class can not be found.
I have a UserControl (XAML file) that I want to show as a new window. Using a tab control is not really an option unfortunately as the user has to be able to arrange windows to see more than one at once.
Any suggestions?
ChildWindow is part of the SDK, you need to add the System.Windows.Controls.dll to access the ChildWindow type.
I'm not sure you can get the ChildWindow to do what you are expecting. A ChildWindow is designed to present a window in a modal manner. However this modal behaviour is really a function of the ChildWindow template. It is possible to re-template to remove the modal behaviour. However I've never tried to manipulate multiple child windows. You could give it a go, the big question would be what happens if you close Child windows in a different order in which they were created?
In order to use a ChildWindow to present your UserControl it would probably be best for you to derive from ChildWindow, instead of UserControl. You may even find it would ultimately be better for you create base class between your specific Xaml and ChildWindow where you would put code that is common to all your windows.
I might be worth you noting the Silverlight 5 will support multiple windows.
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));
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();