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
Try this
What happens is that you’re binding to the
enableCollectionButtonproperty, but you’re not notifying the BindingManager of the change toenableCollectionButton, rather of the change toSelectedRowsCount. The BindingManager doesn’t know they’re related!Also try using Microsoft’s naming conventions,
enableCollectionButtonshould beEnableCollectionButton