views:

20

answers:

1

Hi everybody!

I have a strange situation:

in a .NET CF project there is a class (call it A) which has the following structure:

public partial class A: Form, INotifyPropertyChanged
{
//for simplicity stripping off everything unrelated to this problem

        private int _SelectedRowsCount = 0;
        public int SelectedRowsCount
        {
            get { return _SelectedRowsCount; }
            set
            {
                _SelectedRowsCount = value;
                OnPropertyChanged("SelectedRowsCount");
            }
        }

        public bool enableCollectionButton
        {
            get { return SelectedRowsCount > 0; }
        }

//....
//
//


         void SomeMethod()
{
 //for simplicity:
SelectedRowsCount = 1; //<- HERE NOT FIRING Propertychanged for enableCollectionButton
}
}

The class implements correctly the INotifyPropertyChanged interface which makes the the SelectedRowsCount property to fire a property changed notification (i evaluated this with the debugger). The enableCollectionButton property is databound to some control like so:

someButton.DataBindings.Add("Enabled", this, "enableCollectionButton");

But the enableCollectionButton property does not change (though depending on the value of SelectedRowsCount). This property should be evaluated on a change of the SelectedRowsCount property, BUT IS NOT!!!

Why is this not functioning, what do i miss??

Thanks in advance

A: 

Try this

public partial class A: Form, INotifyPropertyChanged
{
//for simplicity stripping off everything unrelated to this problem

    private int _SelectedRowsCount = 0;
    public int SelectedRowsCount
    {
        get { return _SelectedRowsCount; }
        set
        {
            _SelectedRowsCount = value;
            OnPropertyChanged("SelectedRowsCount");
            OnPropertyChanged("enableCollectionButton"); //This changes too !
        }
    }

    public bool enableCollectionButton
    {
        get { return SelectedRowsCount > 0; }
    }
}

What happens is that you're binding to the enableCollectionButton property, but you're not notifying the BindingManager of the change to enableCollectionButton, rather of the change to SelectedRowsCount. The BindingManager doesn't know they're related!

Also try using Microsoft's naming conventions, enableCollectionButton should be EnableCollectionButton

ohadsc
@ohadsc: Thanks very much!How could i oversee that?!!! I should go oftener for a walk!!Haha! And yes you 're about the naming conventions (usually i do keep the conventions)! Thanks very much again
Savvas Sopiadis
You're welcome !
ohadsc