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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:48:20+00:00 2026-06-04T03:48:20+00:00

I have an class, let’s refer to it as SomeClass. SomeClass implements INotifyPropertyChanged and

  • 0

I have an class, let’s refer to it as SomeClass. SomeClass implements INotifyPropertyChanged and this is coded as follows:

public class SomeClass
{
.
.
.
private bool _isDirty;

public bool IsDirty
{
    get { return this._isDirty; }
    set
    {
    this._isDirty = value;
    this.NotifyPropertyChanged("IsDirty");
    }
}

public event PropertyChangedEventHandler PropertyChanged;

public void NotifyPropertyChanged(string propertyName)
{
    if (this.PropertyChanged != null)
    {
    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
}

I have a form that uses an instance of SomeClass, called instanceOfSomeClass

This property all fires correctly but onto the main issue which is where I have a Save button bound to that property viz.

<Button Content="Save" Height="23" Name="btnSave" IsEnabled="{Binding Path=IsDirty}" Width="60" Margin="10, 10" HorizontalAlignment="Right" Click="btnSave_Click" />

A combo box SelectionChanged event is supposed to change that property is defined as follows:

<ComboBox Name="cboListOfUsers" ItemsSource="{Binding}" SelectionChanged="cboSomeCombo_SelectionChanged"/>

(I have removed parts of the combo box definition that are not pertinent to the question such as styles etc)

Critically the DataContext of the combo box is not set to the instanceOfSomeClass, rather a List of a custom class.

The SelectionChanged event fires and I have code that looks like this:

instanceOfSomeClass.IsDirty = true;
instanceOfSomeClass.User = (ApplicationUser) cboSomeCombo.SelectedItem;

This runs and although it does change the property and raise the appropriate notification it doesn’t enable the command button. I surmise that this is because the DataContext for the combo is different to the DataContext for the command button

I’ve tried changing the DataContext in the SelectionChanged event but this just results in nothing being selected in the combo (the Save button is enabled though!)

Any help would be greatly appreciated

  • 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-04T03:48:22+00:00Added an answer on June 4, 2026 at 3:48 am

    I surmise that this is because the DataContext for the combo is
    different to the DataContext for the command button

    no i don’t think so. You could try that by not binding the ItemsSource directly to the DataContext instead using a member on the datacontext or using RelativeSource, ElementName, directly specifying the source or another binding syntax. I greatly suggest to use a collection from a property and not set the collection as the datacontext (personally i think thats really bad style, {Binding} should only be used very rarely and i use it only when ContentControls are involved).

    Check the Datacontext on the button, use snoop for that it helps greatly by finding bugs like these. Make sure the property is REALLY raised, i can’t count how many times we didn’t step in the actual NotifyPropertyChanged where the bug was.

    Make sure your button doesn’t use a command sowhere because commands change the IsEnabled property in some ways.

    Make sure nobody is overwriting the IsEnabled property, like Triggers, Animations etc.

    Check the output for binding errors or warnings, enable them if you use vs10.

    I will update my answer if you can provide more info, was just to much for a comment.

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

Sidebar

Related Questions

In Visual Studio 2008 (C++) I have a class destructor (Let's call this class
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let's say we have a class foo which has a private instance variable bar
Let's say I have a class Point: class Point { int x, y; public:
let say i have following class: class Shape { public int widht; public List<Point>
Not sure how to implement this scenario: I have a base class let's say
Let's say we have class X with defined constructor X(int value) . Is this
I have a class that represents some business object, such as this: Public Class
I have an abstract class — let's name it Base . This class contains
Let's say I have: class A { public: class B { }; }; Is

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.