Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:46:06+00:00 2026-06-11T12:46:06+00:00

I’m working on a mvvm light toolkit based project. I’ve got a MainView and

  • 0

I’m working on a mvvm light toolkit based project. I’ve got a MainView and a DetailsView with its
corresponding ViewModels. Both VMs are registered for a NotificationMessage.

// MainViewModel.cs and DetailsViewModel.cs
private void RegisterMessages()
{
    Messenger.Default.Register<NotificationMessage>(this, NotificationMessageHandler);
}

When a “ShowDetails” message is received, the MainViewModel calls a service that creates the ‘DetailsView’

// MainViewModel.cs
private void NotificationMessageHandler(NotificationMessage msg)
{
    if (msg.Notification == "ShowDetails")
    {
        _detailsService.ShowDetails(); // Does something like (new DetailsView).ShowDialog()
    }
}

The DetailsView uses the ViewModelLocator to get the existing DetailsViewModal as DataContext.

The DetailsViewModel should receive the “ShowDetails” message to update its internal state or request some data, too.

// DetailsViewModel.cs
private void NotificationMessageHandler(NotificationMessage msg)
    {
        if (msg.Notification == "ShowDetails")
        {
            UpdateViewModel();
        }
    }

Now the problem:
Because I want the DetailsView to be a modal window, I call ShowDialog() on it. This seems to block the messenger untill the DetailsView is closed again. So the DetailsViewModal receives the message after the modal window ist closed. Is there any solution to fix this?

I think it would work, if I could register the DetailsViewModal before the MainViewModel. This would change the order of the MessageHandler-calls and the VM update occures before the blocking ShowDialog(). But the MainViewModel is created and registered first due to it is what it is. The DetailsViewModel is created by the ViewModalLocator the first time it is needed, so it always loses the race.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:46:07+00:00Added an answer on June 11, 2026 at 12:46 pm

    Unfortunately, I was unable to reproduce your specific issue. I fired off a separate thread in my MainWindowView Loaded event handler; a thread which did nothing but continuously send a specific message. I then called ShowDialog() on my SecondWindowView, whose view model was registered to listen to this specific message. The message handler in the second window’s view model executed repeatedly. In fact, the handler was being called even before ShowDailog() was called since my view model was already created by the ViewModelLocator at application startup. I would need to see some more code to get a better idea of what’s going on in your case (i.e. your service that is creating the details window, or something that I can compile to reproduce the issue).

    You might try the following approach, instead, for your child window. Define the following classes somewhere in your application:

    public class ShowChildWindowMessage : MessageBase { }
    public class HideChildWindowMessage : MessageBase { }
    public class DisplayDetailsMessage : MessageBase { }
    

    Now create the following ChildWindowVM class and initialize it in your ViewModelLocator the same way the MainWindowVM is initialized:

    public class ChildWindowVM : ViewModelBase
    {
        private ViewModelBase m_currentContent;
        public ViewModelBase CurrentContent
        {
            get { return m_currentContent; }
            set
            {
                NotifySetProperty(ref m_currentContent, value, () => CurrentContent);
                if (m_currentContent != null)
                {
                    m_currentContent.Refresh();
                    Messenger.Default.Send(new ShowChildWindowMessage());
                }
            }
        }
    
        public ChildWindowVM()
        {
            Messenger.Default.Register<DisplayDetailsMessage>(this, OnDisplayDetails);
        }
    
        private void OnDisplayDetails(DisplayDetailsMessage msg)
        {
            CurrentContent = ViewModelLocator.DetailsViewModel; // or whatever view model you want to display
        }
    }
    

    The Refresh() method would be defined in the DetailsViewModel class and would take care of any initialization you would like to perform before displaying the window. Note that when the CurrentContent property is set then a message is fired off to the MainWindowView to create a ChildWindowView instance in which to display your content.

    The MainWindowView code looks like this:

    public partial class MainWindowView : Window
    {
        private ChildWindowView m_childWindowView;
    
        public MainWindowView()
        {
            InitializeComponent();
            Closing += () => ViewModelLocator.CleanUp();      
    
            Messenger.Default.Register<ShowChildWindowMessage>(this, OnShowChildWindow);
            Messenger.Default.Register<HideChildWindowMessage>(this, OnHideChildWindow);
        }
    
        private void OnShowChildWindow(ShowChildWindowMessage msg)
        {
            m_childWindowView = new ChildWindowView();
            m_childWindowView.ShowDialog();
        }
    
        private void OnHideChildWindow(HideChildWindowMessage msg)
        {
            m_childWindowView.Close();
        }
    }
    

    The last step is to bind the CurrentContent property from the ChildWindowVM class to your ChildWindowView class. This is done in the xaml for your ChildWindowView:

    <Window x:Class="Garmin.Cartography.AdminBucketTools.ChildWindowView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding Path=ChildWindowVm, Source={StaticResource Locator}}">
    
    <Grid>
        <ContentPresenter Content="{Binding Path=CurrentContent}" />
    </Grid>
    

    Now you can display your details from anywhere in your application simply by calling

    Messenger.Default.Send(new DisplayDetailsMessage());
    

    And you can close the window programmatically by calling

    Messenger.Default.Send(new HideChildWindowMessage());
    

    You can also derive as many classes as you want from MessageBase and register for them in your ChildWindowVM class. In each message handler, you can then specify which content to show simply by setting the CurrentContent property to the appropriate view model.

    One more thing, actually. You’ll need to specify the template binding between your views and view models if you actually want to see anything useful in your child window. This can be done via xaml in your application resources:

    <DataTemplate DataType="{x:Type viewmodels:DetailsViewModel}">
        <views:DetailsView />
    </DataTemplate>
    

    Don’t forget to define the namespaces (i.e. “viewmodels” and “views”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm trying to select an H1 element which is the second-child in its group
i got an object with contents of html markup in it, for example: string
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.