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

  • Home
  • SEARCH
  • 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 7738875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:22:48+00:00 2026-06-01T08:22:48+00:00

So my app is basically a shell with a ContentControl that I populate with

  • 0

So my app is basically a shell with a ContentControl that I populate with custom UserControl‘s depending on the user selection of a menu.

But now I’m having a weird behaviour.

I had attached the Content property of the ContentControl to a ViewModel property wich I instantiate on demand. That works great but I’m having two problems.

  1. When I select one option of the menu it creates a new instance of the specified UserControl and set the Content property the shell. That works, cause I see the control and can interact with it, and when I select another option from the menu, it shows me the other UserControl, but, when I select again the previosly selected option it seems to be loading the same previously instantiated control (the right one but with the older input, and I’m doing a new XXXControl() before setting it as the Content property of the ContentControl.

  2. I’m calling a ShowDialog() from inside the custom control via Commands (from the user control view model I call the view via MVVM Light messaging and then show the dialog), and that works. But when I try to close the dialog it show it again the same number of time I select different options from the menu.

For example, I start with A menu and show the dialog, then the close button works, then I goes to B menu and back to A, then the close button works at the second press (two ShowDialog() are being called) and so on…

I don’t know wich part of the code must I paste in order to give a little more of context to this post, but any input will be appreciated. I’m stuck with this (mine) bug.

Code

On the shell view:

<ContentControl Grid.Row="2" Content="{Binding CurrentView}" Margin="15,10"/>

On the shell ViewModel:

if (action == null || action == SEARCH_ACTION)
    {
        ActionsMenuSelected = SEARCH_ACTION;
        var view = new SearchDocumentView();
        CurrentView = view;
    }

On the inner view (SearchDocumentView):

public SearchDocumentView()
{
    InitializeComponent();
    Messenger.Default.Register<NotificationMessage<Entity>>(this, NotificationMessageReceived);
}


private void NotificationMessageReceived(NotificationMessage<Entity> msg)
{
    if (msg.Notification == "ViewResult")
    {
        var view = new DocumentViewer( ServiceLocator.Current.GetInstance<IDataService>(),msg.Content);
        view.ShowDialog();
    }
}

On the inner view (SearchDocumentView) xaml:

<ListBox x:Name="SearchResults"  ItemsSource="{Binding SearchResults}" SelectedItem="{Binding SelectedSearchResult}">
            <ListBox.InputBindings>
                <KeyBinding
                            Key="Enter"
                            Command="{Binding ViewResult}" />
                <KeyBinding
                            Key="Return"
                            Command="{Binding ViewResult}" />
            </ListBox.InputBindings>
            ...

On the inner view (SearchDocumentView) ViewModel:

private RelayCommand _viewResut;

        /// <summary>
        /// Gets the ViewResult.
        /// </summary>
        public RelayCommand ViewResult
        {
            get
            {
                return _viewResut
                    ?? (_viewResut = new RelayCommand(
                                          () =>
                                          {
                                              MessengerInstance.Send(new NotificationMessage<Entity>((Entity)SelectedSearchResult, "ViewResult"));
                                          },
                                          () => ((Entity)SelectedSearchResult!=null)?true:false ));
            }
        }
  • 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-01T08:22:49+00:00Added an answer on June 1, 2026 at 8:22 am

    Why you see your old data I cannot see right now – but I guess you use the same (model)-data for the newly created view.

    The second problem should be here:

    public SearchDocumentView()
    {
        InitializeComponent();
        Messenger.Default.Register<NotificationMessage<Entity>>(this, NotificationMessageReceived);
    }
    

    For each new view your register a Notification, that will show your message box but I don’t see if you unregister those and if you don’t the handler will hold the viewmodel in memory and will still show the messages boxes.

    Even if I got it wrong (is this your “controls”-viewmodel?) it should be something very similar, but you can find this easily by setting a breakpoint to the .Show on your message and looking at the callstack while debugging.

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

Sidebar

Related Questions

I'm writing an app that will basically be like Fraps, but it will push
I created a native Android app that basically hosts a webView control. That webView
How can I build an android app which basically get the inputs from user
I'm making a Android app that basically plays video from a website on the
I'm working on an interface with a 3rd party app that basically needs to
Basically my app is interacting with a web service that sends back a weird
So I'm basically making an app that adds a count to a number and
I'm writing a webapp that basically allows users to kick off shell scripts with
I'm doing a little app that basically has 2 text boxes. You'll enter Fahrenheit
I just inherited a c# 4.0 WinForms app (basically just a small dashboard) that

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.