1

I'm new to WPF and I would like to select multiple controls (let's say I draw a rectangle with the mouse and select the controls that are inside this shape) and change their value togheter. How can I do that? Btw, I'm using MVVM.

In the example below I have 3 sliders and I would like to be able to select them so I can use the keyboard to control all of them at once. I know I can't set the keyboard focus to the 3 of them at the same time. How can I accomplish this task?

    <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Slider IsSnapToTickEnabled="True" Grid.Column="0" Ticks="{Binding Slider1Values}" Value="{Binding Slider1Selected}" Orientation="Vertical" HorizontalAlignment="Center" Margin="10"/>
    <Slider IsSnapToTickEnabled="True" Grid.Column="1" Ticks="{Binding Slider2Values}" Value="{Binding Slider2Selected}" Orientation="Vertical" HorizontalAlignment="Center" Margin="10"/>
    <Slider IsSnapToTickEnabled="True" Grid.Column="2" Ticks="{Binding Slider3Values}" Value="{Binding Slider3Selected}" Orientation="Vertical" HorizontalAlignment="Center" Margin="10"/>
</Grid>
Natan
  • 1,867
  • 13
  • 24
  • [Related](http://stackoverflow.com/q/1838163/1997232) to selection. *Marking* would be easier option (have `CheckBox` for eachs slider to mark them, then currently focused one will change values of all marked `Slider`s). – Sinatr Nov 12 '14 at 16:23

1 Answers1

0

In your KeyUp event (or whatever event you choose) modify the values of all 3 bindings:

    private void Window_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == (Keys.Up)) {
            newValue = oldValue + 10;
        } else if (e.KeyCode == (Keys.Down)) {
            newValue = oldValue - 10;
        }

        this.Slider1Selected = newValue;
        this.Slider2Selected = newValue;
        this.Slider3Selected = newValue;
    }
paul
  • 21,653
  • 1
  • 53
  • 54