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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:23:36+00:00 2026-06-04T12:23:36+00:00

I have a few questions regarding WPF commands. Where should I put confirmation dialogs?

  • 0

I have a few questions regarding WPF commands.

  1. Where should I put confirmation dialogs? Should I show them right inside the command callback function? What if in some areas in the application I don’t want a command to show a confirmation?

  2. If I have a user control that shows items that can be deleted. Should the command be in the application’s view model, and I use it for the item deletion, or should the user control itself also have a command that in turn calls the view model’s function? (Note: the application view model is the only one having the information needed to do this operation)

  3. How can I pass data within a command? I am using mostly DelegateCommand, and upon firing a command for a grid item, I’d like to pass the selected item, otherwise the application’s main view model would have to find the grid and figure out its selection which will hardcode the command to the grid and not make it reusable.

  • 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-04T12:23:38+00:00Added an answer on June 4, 2026 at 12:23 pm

    A bit of this is opinion and style . . . Here’s my approach:

    Question 1:

    I have a utility class that handles any confirmation, and I use the lightweight messaging in MVVM Light to handle communication between the view, the confirmation, and the viewmodel.

    Edit: A bit more information on point 1

    From within my Command, I will send a message along the lines of
    "ConfirmDeletionMessage", which is then picked up by my dialog utility
    class. The dialog utility class displays the appropriate message to
    the user, and checks the results. Based on the results, it will
    either broadcast a "DeletionConfirmedMessage" or
    "DeletionCanceledMessage," which is then handled by the ViewModel to
    either complete or cancel the delete.

    There is some risk involved if you have multiple subscribers to this
    message, as you won’t know what order they’re going to be handled,
    but if you have strict management on message consumers, or ensure
    that they are able to run in a random order, this approach works
    pretty well, and it separates your View and Model code in a testable
    fashion.

    Question 2:

    This is a tough one, and it is going to depend on your overall application. I’m personally a fan of putting it in the item’s viewmodel. That way, you don’t have to worry about your third question as much. Instead, the delete action simply works on the item you’re dealing with. However, if you have to act on data outside of your list item (like removing it from the list), it makes more sense for the command to be on the parent viewmodel.

    Question 3:

    Use the CommandParameter property. You can bind this to whatever you want.

    EDIT to Answer #2

    Mark Green (who commented below) got me thinking. I originally adopted this approach for WP7, and it absolutely suited what I needed to do. However, there are other ways of handling this that should absolutely be considered. Another option is a "confirmation class" that can be used by your viewmodel. If you are using an IoC kernel, this becomes easy to do with constructor / property injection. Alternatively, if you have other methods of getting the class, do so, but do it in a way that you can mock out in testing. It might look something like this:

    public class ExampleViewmodel : ViewModel
    {
          private IConfirmDialogManager _dialogManager;
          public ExampleViewmodel(IConfirmDialogManager dialog)
          {
                _dialogManager = dialog;
          }
    
          // ... code happens ...
          private void DeleteCommand()
          {
                 bool result = _dialogManager.Confirm("Are you sure you want to delete?");
          }
    }
    

    With an IConfirmDialogManager interface that looks like this:

    public interface IConfirmDialogManager
    {
          bool Confirm(string message);
    }
    

    Which you would then implement appropriately.

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

Sidebar

Related Questions

I am a newbie user of Frama-C and have a few questions regarding assertions
I'm very new to TDD world. I have a few questions regarding TDD. Do
I have a few basic questions regarding the syntax and usage of properties in
I have few questions, I want to show the alert window on my Update
I have a few questions regarding JavaScript obfuscation on client side. First question :
I have a few questions regarding differentiation between const and non-const versions of methods
I am a beginner to networking and I have a few questions regarding networking.
I have few questions regarding HornetQ: What are differences between HornetQ core API and
i have a few questions regarding libevent2 and its multithread support. Does libevent support
I have a few questions regarding the Windows Azure Table Storage. Unfortunately my trial

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.