How to manage multiple windows in MVVM

How to manage multiple windows in MVVM

By : Bala Trinadh
Date : November 22 2020, 12:01 PM
I think the issue was by ths following , Well it mainly depends on how your application looks like (i.e. how many windows opened at the same time, modal windows or not...etc).
A general recommendation I would give is to not try to do "pure" MVVM ; I often read things like "there should be ZERO code-behind"...etc., I disagree.
code :
// Main viewModel
public MainViewModel : ViewModelBase
    // EventArgs<T> inherits from EventArgs and contains a EventArgsData property containing the T instance
    public event EventHandler<EventArgs<MyPopupViewModel>> ConfirmationRequested;
    // Called when ICommand is executed thanks to RelayCommands
    public void DoSomething()
        if (this.ConfirmationRequested != null)
            var vm = new MyPopupViewModel
                // Initializes property of "child" viewmodel depending
                // on the current viewModel state
            this.ConfirmationRequested(this, new EventArgs<MyPopupViewModel>(vm));
// Main View
public partial class MainWindow : Window
    public public MainWindow()

        // Instantiates the viewModel here
        this.ViewModel = new MainViewModel();

        // Attaches event handlers
        this.ViewModel.ConfirmationRequested += (sender, e) =>
            // Shows the child Window here
            // Pass the viewModel in the constructor of the Window
            var myPopup = new PopupWindow(e.EventArgsData);

    public MainViewModel ViewModel { get; private set; }

// App.xaml, starts MainWindow by setting the StartupUri
<Application x:Class="XXX.App"

Share : facebook icon twitter icon
MVVM and multiple windows

MVVM and multiple windows

By : user2800966
Date : March 29 2020, 07:55 AM
help you fix your problem Caliburn.Micro provides a WindowManager type with a Show method which can display a view model in a new window, and if that view model implements the appropriate Caliburn.Micro interfaces, the WindowManager will ensure the view model goes through the usual life cycle (i.e. it calls OnActivate, OnDeactivate etc). If your view models derive from the Screen type, then this will be the case.
WindowManager implements the IWindowManager interface, so you can inject this abstraction as a dependency into your ShellViewModel.
WPF Multiple Instances of Windows and MVVM

WPF Multiple Instances of Windows and MVVM

By : Grétar Þór Grétarsso
Date : March 29 2020, 07:55 AM
Any of those help Actually I have this working by using the WindowManager from Caliburn.Micro which seems like an very excellent framework for this type of application. I did look into prism but it seems over complicated and Caliburn is very easy to understand which did meet the requirements. I looked into MVVM Light but the documentation is horrible and lacks examples and I don't have time to figure it out.
MVP vs MVVM: how to manage alert dialogs in MVVM and improve testability

MVP vs MVVM: how to manage alert dialogs in MVVM and improve testability

By : super caco
Date : March 29 2020, 07:55 AM
With these it helps The solution I use for MVVM is mixed, as follows.
From the article from Jose Alcérreca mentioned in the Medium post LiveData with SnackBar, Navigation and other events (the SingleLiveEvent case) referred in the SO answer to Show Dialog from ViewModel in Android MVVM Architecture, I choose the forth option "Recommended: Use an Event wrapper". The reason being that I'm able to peek the message if needed. Also, I added the observeEvent() extension method from this comment in Jose's Gist.
code :
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer

 * Used as a wrapper for data that is exposed via a LiveData that represents an event.
 * See:
 *  https://medium.com/androiddevelopers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150
 *  https://gist.github.com/JoseAlcerreca/e0bba240d9b3cffa258777f12e5c0ae9
open class LiveDataEvent<out T>(private val content: T) {

    var hasBeenHandled = false
        private set // Allow external read but not write

     * Returns the content and prevents its use again.
    fun getContentIfNotHandled(): T? {
        return if (hasBeenHandled) {
        } else {
            hasBeenHandled = true

     * Returns the content, even if it's already been handled.
    fun peekContent(): T = content

inline fun <T> LiveData<LiveDataEvent<T>>.observeEvent(owner: LifecycleOwner, crossinline onEventUnhandledContent: (T) -> Unit) {
    observe(owner, Observer { it?.getContentIfNotHandled()?.let(onEventUnhandledContent) })
class ExampleViewModel() : ViewModel() {
    private val _synchronizationResult = MutableLiveData<LiveDataEvent<SyncUseCase.Result>>()
    val synchronizationResult: LiveData<LiveDataEvent<SyncUseCase.Result>> = _synchronizationResult

    fun synchronize() {
        // do stuff...
        // ... when done we get "result"
        _synchronizationResult.value = LiveDataEvent(result)
exampleViewModel.synchronizationResult.observeEvent(this) { result ->
    // We will be delivered "result" only once per change
Resolving windows in Structure Map or how to manage multiple windows in WPF MVVM?

Resolving windows in Structure Map or how to manage multiple windows in WPF MVVM?

By : Ramesh
Date : March 29 2020, 07:55 AM
wish helps you I think before implement patterns of behavior, such as a Mediator, and the like, need to decide on a generic pattern for easy application structure. For this purpose, namely, for the create independent windows, well suited Abstract factory pattern.
Creation of the windows can be implemented on the side ViewModel using methods such as IDialogService. But I think that this task should be implemented on the side View, because the Window object refers to the View and not to ViewModel. So, you must create MVVM style architecture that it allows create independent windows using design patterns.
powershell manage multiple windows service on multiple remote servers

powershell manage multiple windows service on multiple remote servers

By : Tuck
Date : March 29 2020, 07:55 AM
seems to work fine I have found solution to above.
I've created two separate text files, one for server name say servers.txt and one is for service name say services.txt
Related Posts Related Posts :
  • Replace a # character with a space and a # character
  • DataGrid SelectedItem and CurrentItem on row change and on loosing focus
  • Parse Json to class with C#
  • Publish .exe with Visual Studio Mac
  • c# out causing a no overload for method error?
  • Which Thread resume the method execution after await in Asp.net Web application
  • How to open Asp.Net project in another computer
  • Azure app registrations - SQL Server permission for C# App
  • How to Submit String with 536000 Characters to API
  • Server side TcpClient's stream.read gets no data when a different client (connected to the same port) sends data
  • Add combo-box in windows form grid view by using LINQ query
  • Remove XLL addin when multiple XLL addins are installed
  • Deserialize dynamic json into generic .NET object
  • How to search node in Jobject
  • Iron Webscraper connects to host but doesn't scrape?
  • Change values from textbox at the touch of a button
  • Data access structure with Entity Framework
  • Link Assemblys failed unexpectedly (Xamarin.ios.dll)
  • ASP.NET Core Razor pages - not binding on POST Request
  • How to update appsettings.json from wix custom actions with the values passed as parameter during command line installat
  • Load undefined images from folders
  • How to add a new button in title bar next the minimize button in UWP?
  • Missing DLL in docker image after copying published tree inside
  • One of the identified items was in an invalid format
  • TLS1.2 does not exist with .NET v4.7
  • How do I parse a XML document into object models?
  • Why is a conditional style being set on a html element by Razor is always html encoded incorrectly
  • Counting the amount of repetitions a letter has in a string
  • How to get the encoding of a file in a repository git via C#?
  • Communication between an Azure web application and a windows form app on Azure VM
  • WCF Service - Client receiving CommunicationException after many requests to localhost
  • How to correctly view pdf in browser using DotVVM?
  • Reading part of json into c# object
  • YoutubeAPI v3 - Setting thumbnail returns Completed status, but no thumbnail is set on video
  • Using the SimpleInjector, is it possible to get a singleton by its implementation type?
  • Why the LogLevel rule is not set for my NLog?
  • Converting short? to TimeSpan
  • Publish build artifact through build.cake instead of Azure Devops
  • Unable to get new token using JWT method (C#)
  • Running HttpRequest synchronously C#
  • How to avoid format in "XDocument.Parse(strHtml)"
  • How to update naviation property with new values in EF Core?
  • Queued function not executing with dequeue
  • How to Control Sequence of columns automatically Generated in DataGrid
  • Getting error when try to add a file from library to main project?
  • Aggregate Roots DDD/UoW/Repo/Service
  • How to change the horizontal movement direction of the player in Unity2D?
  • Getting a two dimensional array of all possible unique combination of numbers lower than a mixmum for each cell starting
  • How to get LDAP nested groups from attribute
  • Get array consisting of first values of a list of tuples
  • How do I pass information from my View to my Controller as a Parameter
  • UWP BarcodeScanner Preview: CaptureElement doesn't show any Preview
  • How to register open generic with custom factory method?
  • Change image via in scriptable object in Unity
  • Decreasing value of one float when other go up
  • Xceed CheckComboBox not properly showing selected values from items hardcoded in XAML
  • Why does char array display contents on console while string and int arrays dont in c#?
  • How to prevent custom filters twice calls?
  • c#: remove brackets of certain size if existing including its content
  • Is there a simple way of handling nested Dictionary<string, object> types where object is either string or another
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org