When I click "Add", fill-in data and then "OK", the data has successfully put in the collection but "Add" button is still disabled.
I have to click "Edit" follow by "Cancel" so that the "Add" button become enabled again.
5 Answers, 1 is accepted
Now I know what cause the problem.
The dataform was bound to a ListCollectionView of objects that implement IEditableObject and INotifyPropertyChanged.
By design, those objects raised OnPropertyChanged event on EndEdit or CancelEdit method because there were some changes in their internal properties. This made the dataform think the object has been changed again so it didn't enable navigation and Add New buttons.
My question, can we make the dataform pay attention to only those properties bound to UI element under the dataform, or is there any other solution?
I have a dataform with the same behavior as you described. The add button disables after adding an item. My ItemsSource is bound to a CollectionView of objects that implements IEditable interface.
I wanted to ask you if or how you solved your problem. Any help will be appreciated.
for people who can face this problem too: at the moment I have solved this by using MoveCurrentToPosition(((RadDataForm)sender).CurrentIndex); in RadDataFormCommands.CommitEdit handler. But im not sure if this is an optimal solution.
Another solution it is to make use of the System.Reactive library and instead of a regular property, have a IObservable property to notifiy other objects of changes. The backing field would be a subject and at the end of the EndEdit (and/or CancelEdit) method, the subjects OnNext method would be invoked with the backup field. An abbreviated version would look something like this
public class ViewModel : INotifyPropertyChanged, IEditableObject,
private ViewModel backup;
private readonly ISubject<ViewModel> changesSubject = new Subject<UserViewModel>();
public IObservable<ViewModel> BackupChanges => changesSubject;
public void EndEdit()
this.backupUser.UserName = _userName;
this.backupUser.FirstName = _firstName;
this.backupUser.LastName = _lastName;
this.backupUser.Role = role;
this.backupUser.Password = _password;