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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:31+00:00 2026-05-23T16:06:31+00:00

I am just starting to use commanding with MVVM in an application. I’ve found

  • 0

I am just starting to use commanding with MVVM in an application. I’ve found a number of examples and have tried it both ways in my code. Some examples have the command binding in the xaml like so:

<CommandBinding Command="local:MainWindow.OpenRecentFile" 
                Executed="{Binding OpenRecentFile_Executed}" />
...
<MenuItem Header="{x:Static culture:TextResource.RecentFilesMenuItem}" 
          Command="local:MainWindow.RecentFilesCommand" >

With OpenRecentFile_Executed being a method in the ViewModel and a static ICommand like so:

 public static readonly ICommand OpenRecentFile = 
     new RoutedCommand("Open Recent", typeof(MainWindow));

I have also seen where there is a property on the ViewModel that is of type ICommand that is bound to in the View like so:

<MenuItem Header="Close Current File" 
          Command="{Binding CloseCurrentFileCommand}" 
          CommandParameter="{TemplateBinding DataContext}"/>

and in the ViewModel:

private ICommand closeCurrentFileCommand;
public ICommand CloseCurrentFileCommand
{
    get
    {
        if (closeCurrentFileCommand == null)
        {
            closeCurrentFileCommand = 
                new RelayCommand(param => this.CloseCurrentCedarFile(param));
        }
        return closeCurrentFileCommand;
    }
}

What are the benefits/drawbacks to each method?

  • 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-23T16:06:32+00:00Added an answer on May 23, 2026 at 4:06 pm

    It depends on your design. If you’re going for the quick approach – a Window with back-end code then declaring commands in XAML will probably save you some time and reduce the effort in the long run.

    If you are going for a MVVM app then I would strongly suggest the binding to ICommand as commands in general are ways to manipulate your data (opening/saving/editing) and this should be defined in the ViewModel. Possibly more effort depends on the functionality but MVVM is a great way to go if you’re doing a larger application.

    In the end both will work the same but it’s your design and approach which matter.

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

Sidebar

Related Questions

I've done some Python but have just now starting to use Ruby I could
I am just starting Java RMI and have some problems with when to use
I am just starting to use UML and have came to the following question:
I'm just starting to use core data in my iphone app. I have created
I am just starting to use a web framework. I have decided I really
Just starting to use Ruby on Rails to see what its like. I have
I'm just starting to use constants in Ruby. I have module Constants C1 =
I'm just starting to use Maven with my project. All of my production code
I just starting on WPF with MVVM, so forgive any misconceptions. I have a
I'm just starting to use the composite application libraries for WPF. In my shell

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.