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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:18:13+00:00 2026-05-22T02:18:13+00:00

I have a mvvm(model view viewmodel) silverlight application that has several views that need

  • 0

I have a mvvm(model view viewmodel) silverlight application that has several views that need to be loaded into ContentControls (i made it all in expression blend). What i dont know how to do is, for example, to load one view (user control) in one content control by clicking a button from another view that is in another content control. To make it easier to understand the problem, i need to do something similar to this:

http://www.codeproject.com/KB/silverlight/BlendableVMCom.aspx

with that difference that child1 and child2 are supposed to be loaded into theirown content controls by clicking Call child1 or call child2 buttons.

and example would be appreciated. Thanks in advance!

  • 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-05-22T02:18:14+00:00Added an answer on May 22, 2026 at 2:18 am

    This example is very simplified, but I think you now how to adjust it to your application.

    The main view:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Border x:Name="commandsView">
            <Button Content="Call view 1" Command="{Binding CallView1Command}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5" />
        </Border>
        <Border x:Name="displayedView" Grid.Column="1">
            <ContentControl Content="{Binding CurrentView}" />
        </Border>
    </Grid>
    

    I haven’t created separated views as user controls, here are just borders, which can be replaced by real views.

    Different view models for different views in code behind:

    this.commandsView.DataContext = new CommandsViewModel();
    this.displayedView.DataContext = new DisplayedViewModel();
    

    First view model conains the command which sends the message to another view model:

    public class CommandsViewModel
    {
        public CommandsViewModel()
        {
            this.CallView1Command = new RelayCommand(() => 
              Messenger.Default.Send<View1Message>(new View1Message()));
        }
    
        public RelayCommand CallView1Command { get; set; }
    
    }
    
    public class View1Message : MessageBase
    {
    
    }
    

    To make this example work, download the MVVM Light library.

    The second view model receive the message and creates a view for its property:

    public class DisplayedViewModel : ViewModelBase
    {
        public DisplayedViewModel()
        {
            Messenger.Default.Register<View1Message>(this, obj => 
                this.CurrentView = new TextBlock { Text = "Pressed the button 1 and now here is the view 1" });
        }
    
        private object currentView;
    
        public object CurrentView
        {
            get { return currentView; }
            set
            {
                currentView = value;
                RaisePropertyChanged("CurrentView");
            }
        }
    }
    

    Again, it is possible to use clr object instead of controls and apply data templates in xaml, but there will not be enough space to provide all the resulting code.

    So that is all, the main idea is a some kind of event aggregator, which is the Messenger class in this particular case.

    Without the MVVM Light it will require more code:

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
    
            var events = new GlobalEvents();
            this.commandsView.DataContext = new CommandsViewModel(events);
            this.displayedView.DataContext = new DisplayedViewModel(events);
        }
    }
    
    public class GlobalEvents
    {
        public event EventHandler View1Event = delegate { };
    
        public void RaiseView1Event()
        {
            View1Event(this, EventArgs.Empty);
        }
    }
    
    /// <summary>
    /// Commands which call different views
    /// </summary>
    public class CommandsViewModel
    {
        public CommandsViewModel(GlobalEvents globalEvents)
        {
            this.CallView1Command = new DelegateCommand(globalEvents.RaiseView1Event);
        }
    
        public DelegateCommand CallView1Command { get; set; }
    }
    
    /// <summary>
    /// Model where views are changed and then displayed
    /// </summary>
    public class DisplayedViewModel : INotifyPropertyChanged
    {
        public DisplayedViewModel(GlobalEvents globalEvents)
        {
            globalEvents.View1Event += (s,e) =>
                this.CurrentView = new TextBlock { Text = "Pressed the button 1 and now here is the view 1" };
        }
    
        private object currentView;
    
        public object CurrentView
        {
            get { return currentView; }
            set
            {
                currentView = value;
                RaisePropertyChanged("CurrentView");
            }
        }
    
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    
    }
    

    In this example you must change the DelegateCommand class for something different. Other code will work for everyone.

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

Sidebar

Related Questions

I have a silverlight application (MVVM) with a view that will be used by
I've got this Silverlight Prism application that is using MVVM. The model calls a
I am trying to implement MVVM (Model View ViewModel) pattern for my WinForms application.
I have a silverlight wp7 application and I'm applying the MVVM pattern. The model
I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
On my MVVM silverlight application I have a dataDrid (in the View) and the
I am using MVVM architecture. I have a usercontrol UC as a View Model
I am developing an application with the MVVM model, but I have reached a
I am using the Model-View-ViewModel architecture in a WPF application I am building, and
I am writing an app using the MVVM (Model-View-ViewModel) pattern and am leveraging the

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.