2
votes

I'm trying to create a properties panel in an editor I'm working on, in which I'd like to be able to modify multiple selected items in the view. I can't come up with a straightforward "WPF" way of doing this that doesn't involve either a lot of code behind or type-specific converters or implementations. Any suggestions for the cleanest way to accomplish something like this? Just to make it concrete, here's what I'm talking about:

enter image description here

The "cues" on the right are implemented as an ItemsControl so I'm binding the Properties panel to the SelectedItems property like this:

<ContentControl>
    <ContentControl.Style>
        <Style TargetType="{x:Type ContentControl}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Count}" Value="1">
                    <Setter Property="Content" Value="{Binding Path=[0]}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ContentControl.Style>
</ContentControl>

The DataTrigger ensures that the panel is only available when one item is selected but I'd like to be able to bind to multiple items simultaneously. Ideally the source binding would aggregate the current property values for consensus (and show nothing when multiple values are present). The setting I'm most interested in is Color but it would be nice if there was a at least somewhat generic solution.

2
Could you just use a multi-value converter? Still would be a bit tricky, but it could return null based on the length of the Values array it receives.BradleyDotNET
Am I understanding correctly that you want to basically select multiple and change the color(and other properties) of all of them at once to the same value?Pseudonym
Seems like you should implement such logic in the ViewModel level and use a simple ItemsControl in the UI side for the PropertyGrid-like UI.Federico Berasategui
@PseudoNym01 That's correct.Jeff
@BradleyDotNET Possibly although I'm not sure I exactly see how.Jeff

2 Answers

0
votes

source binding would aggregate the current property values for consensus

Create a new property say named XYZ which aggregates the other properties and bind to it in your Xaml. Unless the other aggregate properties are bound you don't need to call Notify Property Changed for them, necessarily, but you will within them call OnPropertyChanged("XYZ").

Hence any change in the aggregates bubbles up to the new property and its notify property changed bubbles up to the Xaml. Add other properties with similar processes for color/visibility/enabled, etc.

See my answer to MVVM update of calculated properties for an example.

0
votes

My personal solution to this would be to build a a selection list, though this assumes that all of your objects on screen are of the same type. Then once object selection is finished and a property is changed, it would trigger an event that looped through the list and updated the properties will the selected properties. This is a little inefficient in that it will iterate over every property each time, but I think the "automatic" scaling that comes with this would help to balance out having to write extra code.

Here is some pseudocode to more clearly demonstrate what I am talking about:

  1. Item is clicked/selected, add to SelectedList, do this n number of times
  2. Change property/properties
  3. Click apply button, or something similar
  4. Foreach object in SelectedList set each property to selected property
  5. Done

This method will work for any number objects as I mentioned above.