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

  • Home
  • SEARCH
  • 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 6691617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:46:21+00:00 2026-05-26T05:46:21+00:00

I have a template for treeView item: <HierarchicalDataTemplate x:Key=RatesTemplate> <StackPanel Orientation=Horizontal> <TextBlock Text={Binding Path=ID}/>

  • 0

I have a template for treeView item:

<HierarchicalDataTemplate x:Key="RatesTemplate">
    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=ID}"/>
                        <Button CommandParameter="{Binding Path=ID}" 
                                Command="{Binding ElementName=CalcEditView, Path=DataContext.Add}">Add</Button>                            
    </StackPanel>
</HierarchicalDataTemplate>

As a DataContext I have linq entity with ID not null field.

The problem is: if I use DelegateCommand ‘Add’ with CanExecutedMethod:

AddRate = new DelegateCommand<int?>(AddExecute,AddCanExecute);

its called only once and parameter is null (while textBlock shows proper ID value). CanExecute is called before ID property is called (checked with debugger). Seems like before binding to actual parameter wpf is invoking canExecute and forgets about it. Once binding finished and proper value loaded it doesn’t call CanExecute again.

As a workaround I can use command with only execute delegate:

Add = new DelegateCommand<int?>(AddExecute);

AddExecute is invoked with correct ID value and is working perfectly. But I still want to use CanExecute functionality. Any ideas?

  • 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-26T05:46:22+00:00Added an answer on May 26, 2026 at 5:46 am

    In this scenario, it’s better to call the RaiseCanExecuteChanged() on the property used as a parameter for the Command. In your case, it would be the ID property in your ViewModel (Or whichever DataContext you’re using).

    It would be something like this:

    private int? _id;
    public int? ID
    {
        get { return _id; }
        set
        {
            _id = value;
            DelegateCommand<int?> command = ((SomeClass)CalcEditView.DataContext).Add;
            command.RaiseCanExecuteChanged();
        }
    }
    

    The effect will be the same as your solution, but it keeps the Command logic out of code-behind.

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

Sidebar

Related Questions

I have item template with image and textblock. And textblock binded to Name property.
If I have the following data template for a TreeView , what do I
I have a WPF treeview with dynamic levels (TreeView Item uses a Hierachical data
I have created a custom Treeview control and am trying to access the HierarchicalDataTemplate
My tree definition is: <TreeView Name=tree ItemsSource={Binding Children} > <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource={Binding Children}> <CheckBox
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
i have template base.html and some children templates. I don't know how to set
I have template that looks like this: 100 template<size_t A0, size_t A1, size_t A2,
I am running Django trunk and have template Autoescaping on (default). Do I need
I am hosting SpiderMonkey in a current project and would like to have template

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.