I have a datagrid with two columns a and b. Column b represents a percentage.
I want to have a single editable row at the start, and have them fill in column a and b.
In the case that column b is less than 100%, I want to add a new editable row. I want to always add a new row 开发者_StackOverflow中文版when the total percentage is less than 100%.
Any ideas on how to do this (using MVVM)?
The datagrid is bound to an ObservableCollection.
First thing that comes to mind is to handle this completely in ViewModel. You could listen to CollectionChanged of your ObservableCollection, if an item is added, sum up column B, and if the sum is below 100%, add a new item to Observable-collection.
Same thing if you want to support editing of the existing items in the collection. Listen to PropertyChanged event on the items, and if Column B is changed, sum up column B and decide if a new item is needed.
Let me know if you want some sample code for this.
精彩评论