Creating a multiple WPF application using Catel - wpf

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.

Related

C# and UI Automation for external exe

I have a desktop application in wpf than open a new external process (exe).
I can detect this external process window is opened/closed with:
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,...
But... how to detect new events inside this window? For example, inside the windows, when a new dialog is shown, like print settings subwindow.
Thank you
Regards

How to Activate MainWindow in wpf application?

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.

Removing ViewModels in Prism when Closing Window

I have a winform application with data grid rows with some icons.
When the user clicks on one of the icons, a WPF window opens.
I have created this WPF window using Prism i.e. it has shell and regions mapped to view.
The issues I am facing is:
When I tried to close the WPF window, I get the exception "Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed."
I understand that we can resolve the issue by hiding the window instead of closing it.
However, this makes my ViewModel and Services representing the older WPF window.
I have kept the static counter in the ViewModels and observed that every time, I open the WPF window, static count increases which means my old view models are not getting destroyed.
I would like how to handle this scenario correctly so that when I close the window everything related to the window should be disposed off.
I tried to do container.dispose in ShellViewModel, however, still it did not work.
There are two aspects here. Firstly, you can use either RegionMemberLifetimeAttribute on your view model or implement IRegionMemberLifetime to make Prism create a new instance each time.
Secondly, you have to create your own RegionBehavior (or take it from this Github Issue) to make Prism dispose view models.

wpf window.open, hide window when main view clicked

I am new to WPF and have two windows in a solution. Both are opened using Window.Open().
However there is a difference in behaviour that I don't understand. When one of the windows is opened, if you click the view that launched it the new window is minimised behind the main view, so you can interact with it.
The other window, when opened and you click the main view stays where it is and does not get hidden.
How can I get this window to show the same behaviour as the first?
I figured this out, by removing the parent child relationship in the window I was able to get the functionality I desired.

How to launch RoutedCommand on application level in multiple windows pattern?

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));

Resources