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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:33:54+00:00 2026-06-01T03:33:54+00:00

I have a scenario where at least 2 screens will be displayed at the

  • 0

I have a scenario where at least 2 screens will be displayed at the same time that have the same source. On one screen this data is read-only, on other is editable. I need data on both screens to be synchronized. Also, data can be modified by different users.

Lets say that this is the sequence of actions:

  1. user opens a screenA that contains read-only data from collectionA
  2. User needs to add new items to collectionA, so screenB opens
  3. user adds 3 new items on screenB, and then closes it
  4. collection on screenA needs to have new items in it

There could be cases where more than 2 screens contain data from the same source (collection type).

I am using MVVM light and ViewModelLocator pattern to expose ViewModels to Views. Currently I fetch data in ViewModel’s constructor. This means that if I cache ViewMOdel instance for reuse, I will fetch the data only once, all screens will use the same collection as source, so sync is done automatically. This also means that if other user on network changes data, new data will never be visible, since data is fetched only once (during ViewModel creation).

Another approach would be that ViewModelLocator returns new instance of ViewModel each time it is requested. This means that fresh data from database is always fetched, so issue with other network users changing data no longer exists. However, in this case each ViewModel will contain different instance of collection data, so only editing of data is being automatically synchronized, adding/deleting an entity is not being synchronized automatically.

So, what is the best way to have fresh data acquired when a ViewModel is requested, and also having data being synchronized between different screens?

  • 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-01T03:33:56+00:00Added an answer on June 1, 2026 at 3:33 am

    I did a poor job of explaining this in my comments so I created an example of what I was talking about. It’s using CM but the idea can be transferred to MVVM-light.

    I created 2 view models: SharingScreen1ViewModel and SharingScreen2ViewModel and 2 Views: SharingScreen1View and SharingScreen2View.

    Each VM gets the SharedViewModel singleton injected. From the left nav you can toggle between the 2 Views. The SharedDataViewModel properties are initially set in the OnInitialize method that lives in SharingScreen1ViewModel. Then the values can be changed in SharingScreen2ViewModel by clicking the button. Toggle back to View one and the values have changed for it as well.

    When I mentioned the DispatcherTimer, I was referring to a requirement I had to refresh a bit of data every 30 seconds. The timer was one of many ways to update this data. As you can see in this example the data is being set one time when the first ViewModel is initialized and the data is being set again in another ViewModel when the user clicks a button.

    Interface SharedViewModel implements:

     public interface ISharedViewModel
        {
            string FirstName { get; set; }
            string LastName { get; set; }
            string Address { get; set; }
        }
    

    SharingScreen1ViewModel:

     [Export(typeof (SharingScreen1ViewModel))]
        public class SharingScreen1ViewModel : Screen
        {
            [ImportingConstructor]
            public SharingScreen1ViewModel(ISharedViewModel sharedViewModel)
            {
                DisplayName = "Shared Data Screen 1";
    
                SharedViewModel = sharedViewModel;
            }
    
            public ISharedViewModel SharedViewModel { get; set; }
    
            protected override void OnInitialize()
            {
                base.OnInitialize();
    
                SharedViewModel.FirstName = "Jimmy";
                SharedViewModel.LastName = "Hugh";
                SharedViewModel.Address = "555 South St.";
            }
        }
    

    SharingScreen2ViewModel:

    [Export(typeof (SharingScreen2ViewModel))]
        public class SharingScreen2ViewModel : Screen
        {
            [ImportingConstructor]
            public SharingScreen2ViewModel(ISharedViewModel sharedViewModel)
            {
                DisplayName = "Shared Data Screen 2";
    
                SharedViewModel = sharedViewModel;
            }
    
            public ISharedViewModel SharedViewModel { get; set; }
    
            public void ChangeSharedData()
            {
                SharedViewModel.FirstName = "New First Name";
                SharedViewModel.LastName = "New Last Name:";
                SharedViewModel.Address = "New Address";
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a Javascript-generated web page that someone else wrote a long time
We have a scenario where we have built an API that we will provide
I have a C# application that must insert one parent record, and at least
I have scenario where I have to use the same XSD element for different
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario in which I have to run multiple commands one after
I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
I have a scenario where combobox can have same string values. for exa combo
Scenario: 4 users launch separate instances of the same client program (Winforms) that is
Scenario: I have a document I created using LaTeX (my resume in this case),

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.