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 8552451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:25:35+00:00 2026-06-11T14:25:35+00:00

I ‘ve recently started working with WPF using MVVM light and I have the

  • 0

I ‘ve recently started working with WPF using MVVM light and I have the following (simple scenario).

  1. MainWindow contains a listbox of elements.

  2. When one is selected and the button is clicked, I fire a command:

    ReservoirViewerCommand.Execute(null);
    
  3. On the viewmodel class I instantiate the command and send a message with the selected object:

    ReservoirViewerCommand = new RelayCommand(OpenReservoir);
    private void OpenReservoir()
    {
        Messenger.Default.Send(new LaunchShowReservoirMessage(){Reservoir=SelectedReservoir});          
    }
    

    where:

    class LaunchShowReservoirMessage:MessageBase
    {
        public Reservoir Reservoir { get; set; }
    }
    
  4. The mainview registers the message and opens a new child window:

    private void RegisterMessages() 
    {
        Messenger.Default.Register<LaunchShowReservoirMessage>(this,OnLaunchShowReservoir);
    }
    
    public void OnLaunchShowReservoir(LaunchShowReservoirMessage msg) {
        var showReservoir = new ReservoirViewerView();
        showReservoir.Show(); 
    }
    

What I need is that the new ViewModel (ReservoirViewerViewModel) can somehow get hold of the passed object through the message so that I can then display the details of this object on the child window.

I did some step-by-step debugging and the ViewModel constructor seems never to be reached.

  • 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-11T14:25:36+00:00Added an answer on June 11, 2026 at 2:25 pm

    “I did some step-by-step debugging and the ViewModel constructor seems never to be reached.”

    Make sure that you are actually binding your view to your view model using one of the following:

    In CodeBehind

    var showReservoir = new ReservoirViewerView();
    showReservoir.DataContext = ViewModelLocator.ReservoirViewerViewModel; //static property
    //OR showReservoir.DataContext = new ReservoirViewerViewModel();
    showReservoir.Show();
    

    In Xaml View

    <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=ReservoirViewerViewModel, Source={StaticResource Locator}}">
        <!--Use the non-static property in your ViewModelLocator-->
    
        <Grid />
    </Window>
    

    In Xaml Resources

    <DataTemplate DataType="{x:Type viewmodels:ReservoirViewerViewModel}">
        <views:ReservoirViewerView/>
    </DataTemplate>
    

    “What I need is that the new ViewModel (ReservoirViewerViewModel) can somehow get hold of the passed object through the message so that I can then display the details of this object on the child window.”

    Simply register for the same message in your ReservoirViewerViewModel class:

    Messenger.Default.Register<LaunchShowReservoirMessage>(this, (msg) =>
    {
        var reservoir = msg.Reservoir;
    });
    

    FYI, if you derive your message class from GenericMessage<[content type]> instead of MessageBase, then you can use the already-defined Content property of the GenericMessage class. For example:

    public class LaunchShowReservoirMessage: GenericMessage<Reservoir>
    {
        public LaunchShowReservoirMessage(Reservoir content) : base(content) { }
    }
    

    And then:

    Messenger.Default.Register<LaunchShowReservoirMessage>(this, (msg) =>
    {
        var reservoir = msg.Content;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have the following tasks in my deploy.rb namespace :unicorn do desc stop unicorn
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to create a RegEx expression that will successfully parse the following
I recently got a new cable modem from my ISP (Rogers in Canada; old
I'm creating a web service to transfer json to an iPhone app. I'm using
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.