Good day. I am writing an application on WPF using MVVP and Prism. There is a data table, each row is represented by a simple view model. There is a task - to add the ability to edit several lines at a time, i.e. multiedite. The problem is the following - if some property of the selected rows is the same for all rows, then the form needs to load the values ​​of this property. Those. if 10 lines are selected and all these lines (read view model) are Size = 10, then when opening the form of the editor this field should be set to 10.

The problem is how to determine such properties. The only idea is to create a collection containing the names of all properties (13 pieces). Use foreach to go through this collection. On each pass, extract the property value from all selected rows (through reflection) and compare. But this approach is quite expensive. Mb Is there an easier way?

The second idea is to memorize the values ​​of all properties from the first line (VM) and then compare all the other lines with these parameters. Like this:

var size = selectedItems.First().Size; if (selectedItems.All(item => item.Size == size) { // do some work } 

But this option also seems rude. The main problem is that because of such checks, the form with the editor will appear with a delay (if a large number of lines are selected), which is not good. But if I don’t find an elegant solution, I’ll have to do it in the forehead and use asynchrony.

  • one
    Reflection cost? Compared to what? (What do you think, how does Binding work for VM?) - VladD
  • Is the type of VM strings known in advance? - VladD
  • one
    @VladD "What do you think, how does Binding work with VM?" - i2.kym-cdn.com/photos/images/newsfeed/000/217/594/FIHci.jpg - andreycha
  • @VladD I think that reflection is expensive because maybe 20-30 lines per sample. Then you have 20-30 times to extract 13 parameters through reflection and compare them. Thus the form with the editor will open with a delay. But I can be wrong. All strings (ie VM) of the same type. Another idea came up - add to the description. - Vitaly Efimov
  • @ VitaliyEfimov: Okay, is this one type fixed? If so, why not just talk to him? - VladD

0