0
votes

If I have a button (bound to Command 'OpenOtherWindow') that opens a DataWindow by using IUIVisualizerService.Show(viewModel), how can I prevent another instance of said DataWindow to open?

I do not think that creating a Singleton ViewModel is the correct way to do it and having a boolean 'IsWindowOpen' in the ViewModel where my 'OpenOtherWindow' Command is located would not be very MVVM, although this is the current way we have done it.

How would I do it in Catel?

1

1 Answers

1
votes

The key is to create a service that manages the state and instances of the windows. Then you never have to worry about the actual behavior and can change it in one place.

Then you can just call the following (pseudo) code:

_myFeatureService.Show();

In this service you can keep track if the window is already open and open the window if not. If you want to change this behavior in the future, you only have to do it in a single location: the service.