title: WPF binding to the same property of multiple objects in a collection
body: <p>I'm trying to create an interface using WPF that can display and modify the properties of multiple selected objects at once.  I know this must be possible (the property grid in Visual Studio does it) but I haven't been able to find any information or examples on how to achieve it.  I have found a lot of information on MultiBinding, but the canonical use case of that appears to be to bind one UI field to multiple properties on the same object while I'm trying to do the opposite - binding a UI field to the same property on multiple objects.</p>
  
  <p>To be more explicit, the behaviour I want to create is this:</p>
  
  <ul>
  <li>If a single object is selected, the properties of that object are
  displayed</li>
  <li>If more than one object is selected, properties are displayed according to the following logic:
  
  <ul>
  <li>If all selected objects have the same value in that property, display the value</li>
  <li>If the selected objects have different values in that property, display '[Multi]' (or similar)</li>
  </ul></li>
  <li>When a value is entered, all selected object have the bound property set to that value.</li>
  </ul>
  
  <p>By way of example, here is an old WinForms form of mine that does the same thing and which I am more-or-less trying to recreate in WPF.  In that case I dealt with it in the code-behind without data binding, an experience I'm not particularly keen to repeat.</p>
  
  <p>With one item selected:</p>
  
  <p><a href="https://i.stack.imgur.com/88y1I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/88y1I.png" alt="enter image description here"></a></p>
  
  <p>With several items selected (Element Type, Material and Beta Angle properties the same, others different):</p>
  
  <p><a href="https://i.stack.imgur.com/3s71C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3s71C.png" alt="enter image description here"></a></p>
  
  <p>Some other considerations for my particular use-case:</p>
  
  <ul>
  <li>Pretty much the whole UI of my application needs to work in this way,
  so the more easily repeatable the better</li>
  <li>The number of selected items could range from 1-100000 (though will more typically be around the order of a few dozen - some slight lag on huge selections is probably OK provided it doesn't become unusable)</li>
  <li>There will be several different types of data I'll want to make editable, each with its own bespoke interface (i.e. I don't actually want a generic Property Grid solution)</li>
  <li>The datatypes I'm binding to are defined in a separate and publically-available library that I (partly) write but that several other people and projects use.  So, I <em>can</em> modify those types if I absolutely have to but I'd rather not do anything too drastic to them.</li>
  </ul>
  
  <p>My current best-guess for how to do this would be to use a MultiBinding (or a custom sub-class of it), track changes in the underlying collection and programmatically add or remove bindings to the properties on each object to the MultiBinding Bindings collection, then write an IMultiValueConverter to determine the display value.  However, that seems like a bit of a fiddle, not really what MultiBindings were designed for and internet opinion appears to disfavour using MultiBindings except for where absolutely necessary (although I'm not entirely sure why).  Is there a better/more straightforward/standard way of doing this?</p>