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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:25+00:00 2026-06-02T03:11:25+00:00

I have built a user control (ctlToolbarEdit) that has some buttons on it –

  • 0

I have built a user control (ctlToolbarEdit) that has some buttons on it – but for simplicity sake let’s say there is one button: cmdSave.

I want ctlToolbarEdit to expose a IsSaveEnabled property that when set to true sets cmdSave.IsEnabled = true, and (obviously) when false sets cmdSave.IsEnabled = false.

Finally, I want to be able to bind to that property .. I want to bind IsSaveEnabled to the IsValid property of the View Model the form hosting the control is bound to

So. Here is the code behind for ctlToolbarEdit

    private readonly DependencyProperty IsSaveEnabledProperty = DependencyProperty.Register("IsSaveEnabled", typeof(bool), typeof(ctlToolbarEdit));

    public ctlToolbarEdit()
    {
        InitializeComponent();
    }

    public bool IsSaveEnabled
    {
        get { return (bool)GetValue(IsSaveEnabledProperty); }
        set 
        {   
            SetValue(IsSaveEnabledProperty, value);
            cmdSave.IsEnabled = value;
        }
    }

and here is the XAML of the form that is hosting this user control:

<ctl:ctlToolbarEdit IsSaveEnabled="{Binding IsValid}" />

As a test, I also added this line of XAML to the form hosting ctlToolbarEdit (so it is replicating the behaviour I am trying to produce):

<Button Name="cmdSaveTest" Content="Save" IsEnabled="{Binding IsValid}" />

My results are this:

  • The Button I added works as expected. Whenever the IsValid property changes then the IsEnabled value of the cmdSaveTest button changes (I can see it enabling/disabling). This tells me that the IsValid property is firing properly … in other words I CAN bind to that property, so I am happy that the binding to that property and the view model are all okay.

  • The cmdSave button within ctlToolbarEdit does nothing.

In fact: I put some breakpoints on the getter and setter of the property in ctlToolbarEdit and these never seem to fire.

Could anyone please tell me what painfully obvious thing I have overlooked?

EDIT

Typical. You spend hours searching, finally bite the bullet and post on Stack Overflow, and almost immediately find something that goes to answer your question.

I now know:

  • My property getter and setter are ignored by the CLR; it invokes GetValue and SetValue directly. This is why my breakpoints are not being honoured (that code is not actually firing!) and why the IsEnabled property of cmdSave is not working.

So: that all said … how do I actually achieve what I want to achieve, then? Help gratefully appreciated.

EDIT

Ok … so more progress; I see you use the PropertyMetadata. I added:

, new PropertyMetadata(new PropertyChangedCallback(OnIsSaveEnabledChanged))

to the IsSaveEnabledProperty DependencyProperty statement (making it:

private readonly DependencyProperty IsSaveEnabledProperty = DependencyProperty.Register("IsSaveEnabled", typeof(bool), typeof(ctlToolbarEdit), new PropertyMetadata(new PropertyChangedCallback(OnIsSaveEnabledChanged)));

But now the OnIsSaveEnabledChanged method I need to write has to be ‘static’, and I cannot get to cmdSave within that method.

Now I really am stuck. Any help?

DS

  • 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-02T03:11:26+00:00Added an answer on June 2, 2026 at 3:11 am

    With a typical MVVM pattern, you would do this the other way around: Your command’s CanExecute/IsEnabled property would control the IsEnabled property on your control. So, When your viewmodel decides that saving is unavailable, it would cause your command’s CanExecute/IsEnabled flag to be false, and any controls that use that command would disable themselves. For an example, have a look at how a Button control works with an ICommand.

    http://msdn.microsoft.com/en-us/library/ms752308.aspx

    http://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx#sec10

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

Sidebar

Related Questions

I have built a User Control library that has a reference to a WCF
I have a model that has a ForeignKey to the built-in user model in
I have a custom control that mimics to some extent the built in ASP.Net
I am working on a user control that has some dependency properties, namely; public
I currently have built a system that checks user IP, browser, and a random-string
I have several different user controls that get built dynamically and added to a
I have an ASP.NET MVC page that has left Menu Navigation that is built
I have built a User Control composed, as usual, of a XAML part and
I would like to have a textbox that lets a user enter some text
I have built a simple Eclipse plugin where a user may use a TableViewer

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.