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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:44:48+00:00 2026-05-15T20:44:48+00:00

In the application I’m building, the user may perform something in one view (backed

  • 0

In the application I’m building, the user may perform something in one view (backed by a view model) that should trigger an action in one or more other view models. Each of these other vms needs the ability to veto (a.k.a. cancel) the action performed in the first v/vm pair.

Example:

  1. User clicks on an account in a DataGrid control displayed by the accounts list view. DataGrid event handler traps the click and tells vm. Vm notifies other vms of proposed change.
  2. Since user has made unsaved edits to a record in another other view, other vm tells first vm that the proposed selected account change is rejected.
  3. When accounts list vm receives this rejection, it tells DataGrid to keep the selected account set as it was. If no rejection had been received, accounts list vm would have allowed DataGrid selected item change to occur.

A similar scenario would be when the user initiates application shutdown. Interested vms need a way to know that shutdown is proposed and have the option to cancel shutdown.

The view models should be loosely coupled, so direct event subscriptions between them is undesirable.

How would you suggest implementing this intra-view model communication?

Would use an event aggregator to “broadcast” an account changing event be a wise approach? The event argument object would include a bool Canceled property. A subscribing vm that wants to cancel the change would set Canceled = true.

Thank you,
Ben

  • 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-15T20:44:48+00:00Added an answer on May 15, 2026 at 8:44 pm

    I think your last paragraph suggests a good solution.

    Using the MVVM Light Toolkit, I would use messaging with a callback to send the message out and allow any number of subscribers to call back with a cancellation.

    public class AccountSelectedMessage : NotificationMessageAction<bool>
    {
        public AccountSelectedMessage(Account selectedAccount, Action<bool> callback) : base("AccountSelectedWithCancelCallback", callback)
        {
            SelectedAccount = selectedAccount;
        }
        public AccountSelectedMessage(object sender, Account selectedAccount, Action<bool> callback) : base(sender, "AccountSelectedWithCancelCallback", callback)
        {
            SelectedAccount = selectedAccount;
        }
        public AccountSelectedMessage(object sender, object target, Account selectedAccount, Action<bool> callback) : base(sender, target, "AccountSelectedWithCancelCallback", callback)
        {
            SelectedAccount = selectedAccount;
        }
    
        public Account SelectedAccount { get; private set; }
    }
    
    public class AccountListViewModel : ViewModelBase
    {
        public RelayCommand<Account> AccountSelectedCommand = new RelayCommand<Account>(AccountSelectedCommandExecute);
    
        private void AccountSelectedCommandExecute(Account selectedAccount)
        {
            MessengerInstance.Send(new AccountSelectedMessage(this, AccountSelectionCanceled));
        }
    
        private void AccountSelectionCanceled(bool canceled)
        {
            if (canceled)
            {
                // cancel logic here
            }
        }
    }
    
    public class SomeOtherViewModel : ViewModelBase
    {
        public SomeOtherViewModel()
        {
            MessengerInstance.Register<AccountSelectedMessage>(this, AccountSelectedMessageReceived);
        }
    
        private void AccountSelectedMessageReceived(AccountSelectedMessage msg)
        {
            bool someReasonToCancel = true;
            msg.Execute(someReasonToCancel);
        }
    }
    

    As you can see, this process would need to be asynchronous and take into account that you don’t know how many recipients of the message could cancel, or how long they would take to respond.

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

Sidebar

Related Questions

The application my team is currently developing has a DLL that is used to
My application has a need to let the user choose a date from a
What application should I use for creating Flash animations for a website?
Application I develop requires several data sources (2 RDBMS and one file storage) to
Application : Nerddinner. This SP is for an inserting password for newly created User.
I make a distributed embedded application that will make use of several micro-controllers. The
Application : It has 3 views Views A,B,C. There is a Alert on View
Application deals with strings that represent decimals that come from different cultures. For example
Application flow An input file consists of multiple logical documents. Extract one input logical
Application able to record error in OnError, but we are not able to do

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.