Hello Sushma,
I modified your sample to add an implemention for the Command in the Person object. When the command is executed, I disable the button. I also updated the sample to add columns to the grid and bind the grid to a view model which includes a collection of people. When I press the button for some rows those buttons become disabled. I am then able to select other rows without the button’s states changing.
Please see my sample and let me know if this helps resolve you issue or you are still seeing a problem. My modified sample was tested on build 13.2.20132.2300 in NetAdvantage for WPF 2013 Volume 2.
Let me know if you have any questions.
Sincerely,
Valerie
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
This seems to work. So now I have a DelegateCommand in each instance of the Person class. But I create my Person objects in my Model so the CanCommandExecute and CommandExecute would go into the model. I am not comfortable with it. I would rather have it into the ViewModel class.
What I really want is a single command in my view model and bind my XamDataGrid's last column to this command. The command must execute on the row in which it lies.
I tried the same by creating an Observable collection the same as you did, but instead of putting the command in the Person class, I put it in the view model. I bound the button in the view with this command passing in the corresponding row as parameter. But I am facing a strange issue here where whenever my underlying observable collection is cleared and reloaded, my XamDataGrid doesn't get loaded. So the button's which are bound there, their CanExecute deosn't get fired. And so sometimes the first button looks disabled and sometimes third in any random order. Of course when I click on it, if it is supposed to be disabled, the CanExecute runs and returns false. However, the button still remains enabled.
I hope you got my problem. So what I really want is a single command in my ViewModel bound to the view's last column's buttons and getting in the row as parameter whenever I click on the command.
If you would like to move the command to the ViewModel, I would suggest adding a property to the person bound in ViewModel and use this property to bind the IsEnabled property of the button so that the button is automatically enabled/ disabled when the person can be updated.
See modified sample.
Please let me know if you have any questions.
Instead of binding IsEnabled of the button separately, can't I directly bind to the DelegateCommand(Execute, CanExecute) and use the CanExecute to determine if my button must be enabled or not? Having IsEnabled in my DataSource again scatters my DelegateCommand's functionality with Execute in ViewModel and CanExecute in the DataSoucrce.
The XamDataGrid uses virtualization to enhance performance, therefore a cell value presenter that was previously used for a different cell may be recycled to use for a new cell when scrolling. Due to this, you should use a binding to the IsEnabled property of the button to ensure that the state is correct for the underlying data item. If you do not want to have this property in your underlying class (ex Person) you could bind the IsEnabled property to a unique value(s) in the person class and then use a converter to check if the button should be enabled.
That's what seems to be happening in my case. The button being in ViewModel and with the virtualization of XamDataGrid, it keeps dancing around. It is working fine with having an enabled property. Thanks.
I am glad I was able to help.
Please let me know if you have any other questions.
Sincerely,Valerie Developer Support Supervisor - XAMLInfragisticswww.infragistics.com/support