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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:11:13+00:00 2026-05-29T05:11:13+00:00

Little puzzled If i have a button in a wpf window and bind it

  • 0

Little puzzled

If i have a button in a wpf window and bind it to a DelegateCommand

<Button Grid.Row="1"  Content="Remove" Command="{Binding CommandDelete }" />

And in my simple viewmodel i attach

CommandDelete = new DelegateCommand<string>(OnDeleteExecute, OnDeleteCanExecute);

If the button is to be enabled when i choose an item from a list i can bind the list selecteditem to property in my viewmodel

Report selectedReport;
            public Report SelectedReport
            {
                get { return this.selectedReport ;}
                set { this.selectedReport = value;}
            }
private bool OnDeleteCanExecute(string commandParameter)
            {
                return (this.selectedReport != null);
            }

This seems fine to me so far and the only thing missing is to raise a CanExecute event for the specific button in the setter for SelectedReport

CommandDelete.RaiseCanExecuteChanged();

This works but my question is if i have 10 button do i need to call RaiseCanExecuteChanged for each and every button each time a item is selected or is there as smarter way

  • 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-29T05:11:14+00:00Added an answer on May 29, 2026 at 5:11 am

    Usually I place my RaiseCanExecuteChanged() in the PropertyChanged event for that class.

    For example, if DeleteCommand.CanExecute is based on the SelectedReport property, I’ll hook into the PropertyChanged event of the ViewModel and raise the CanExecuteChanged event anytime SelectedReport changes.

    void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "SelectedReport")
            DeleteCommand.RaiseCanExecuteChanged();
    }
    

    This keeps all the logic in one central place and ensures the CanExecuteChanged gets raised whenever one of the parameters changes.

    The other alternative is to switch from using a DelegateCommand to a RelayCommand, which automatically raise it’s CanExecuteChanged when a property changes. I would assume there’s a performance difference, however have never noticed one.

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

Sidebar

Related Questions

I'm a little puzzled with QueryStrings and ActionResult I have a URL coming in
I'm a little puzzled with this one. I have a Collection called AllProducts, which
I've been a little puzzled with this as I have not seen many examples
I'm going through a Fortran code, and one bit has me a little puzzled.
I am a little bit puzzled as to how I can optimize my program
A little background: I am loading a WPF UI from a database which is
I have a main activity with a number of buttons. Each button is starting
I'm puzzled about the correct use of bind variables with dates in Oracle. This
I've got a little puzzler here for the bash scripting experts... I have a
I am a little puzzled why the following is not working, button_ONE does 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.