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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:28:35+00:00 2026-05-26T04:28:35+00:00

When developing, I like to try and understand more than just do this. Especially

  • 0

When developing, I like to try and understand more than “just do this”. Especially with WPF, I like to understand BOTH aspects of the bindings… both from the GUI (xaml) and from the code-behind. That being said, I am wondering what the code equivalent would be for the following.

I have a ViewModel with some pre-defined “ICommand” instances, such as add, edit, save, cancel, exit, whatever — and they work as expected. Now, looking at the binding of the View (Window) that has a button on it, I have it’s binding to the commands, something like.

<Button Command="{Binding ExitCommand}" Content="Exit" ... />

and this properly does what I expect for allowing the form to exit (and do whatever else I’m playing with).

What would the code-behind look like for this. I know that with properties, such as IsEnabled or IsVisible are bound to dependency object / properties, but I don’t understand the correlation when binding to a command’s execution. Thanks.

  • 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-26T04:28:36+00:00Added an answer on May 26, 2026 at 4:28 am

    You create the Command Binding the same way you would any other binding in code behind.

    For example,

    Binding b = new Binding();
    b.Source = myViewModel;
    b.Path = new PropertyPath("ExitCommand");
    MyButton.SetBinding(Button.CommandProperty, b);
    

    Command bindings expect to be bound to an object of type ICommand. When they get executed, such as on a Button Click, they first call ICommand.CanExecute() and if that is true then they call ICommand.Execute(). If the CommandParameter property is set then that is used when evaluating CanExecute and Execute

    With WPF Buttons that have a Command binding, the IsEnabled property is automatically bound to the result of ICommand.CanExecute. The CanExecute method is run once when the button is first loaded, and run again anytime the Command Binding changes.

    If you want it to update more frequently, such as when the CommandParameter changes, you need to hook up something extra to update the binding when the CommandParameter changes. Most RelayCommands I see have this built-in, such as MVVM Light’s RelayCommand, althought other commands such as Microsoft PRISM’s DelegateCommand do not have this behavior by default.

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

Sidebar

Related Questions

I am thinking of developing an application like this: My application has a google-service-account
I would like to try developing ASP.NET and ASP.NET MVC apps in F# .
I'll try to sum this up as best as possible. I'm developing a web
I have a try-catch block that iterates over a set of records like this:
When developing an ERP-like software or any other complex business system, what resources do
I´m developing a ebay-like system in .NET/C# ... Is Lucene a good option to
I'm developing an installation like cocoa application wich needs to take care of some
I am developing a database-like application that stores a a structure containing: struct Dictionary
So suppose I'm developing a chess-like program using Java's Swing. I added a MouseListener
I would like to get started developing games with Flixel, but im on a

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.