Message 1 of 4
Press Shift to select multiple boxes in WPF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, I’m creating a form in WPF but I can’t press Shift to select multiple boxes though I have set the SelectionMode to Extended. Can you look at the XAML code below and tell me why?
```
<Window x:Class="Practice.CopyFilterCurrentModel.CopyFilterCurrentModelWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Practice.CopyFilterCurrentModel"
mc:Ignorable="d"
Width="600"
Height="550"
ShowInTaskbar="True"
WindowStartupLocation="CenterScreen"
Title="Copy Filter Current Model"
ResizeMode="CanResize">
<Grid>
<!-- Define rows in the Grid -->
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<!-- Source GroupBox -->
<RowDefinition Height="*"/>
<!-- Destination GroupBox -->
<RowDefinition Height="Auto"/>
<!-- Buttons -->
</Grid.RowDefinitions>
<!-- GroupBox with Source Header -->
<GroupBox Header="Source" BorderBrush="Gray" VerticalAlignment="Stretch" Margin="10" Grid.Row="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<!-- Ensures ListView expands -->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<!-- Label width -->
<ColumnDefinition Width="*"/>
<!-- ComboBox and ListView width -->
</Grid.ColumnDefinitions>
<!-- Source View ComboBox -->
<Label Content="Source View: " Margin="10 0 0 0" VerticalAlignment="Center"/>
<ComboBox x:Name="cbb_SourceView" Grid.Column="1" Margin="0 5 17 5" SelectionChanged="cbb_SourceView_SelectionChanged" HorizontalAlignment="Stretch"/>
<!-- Filter ListView with ScrollViewer -->
<Label Content="Filters: " Grid.Row="1" Margin="10 10 0 0" VerticalAlignment="Top"/>
<ScrollViewer x:Name="sv_Filters" Grid.Column="1" Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" CanContentScroll="True">
<ListView x:Name="lv_Filters"
SelectionMode="Extended"
PreviewMouseWheel="ListBox_PreviewMouseWheel"
MinHeight="200">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}"
VerticalAlignment="Center"
Margin="0,0,5,0"/>
<TextBlock Text="{Binding}" VerticalAlignment="Center" IsHitTestVisible="False"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
</GroupBox>
<!-- GroupBox with Destination Header-->
<GroupBox Header="Destination" BorderBrush="Gray" VerticalAlignment="Stretch" Margin="10" Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<!-- Label width -->
<ColumnDefinition Width="*"/>
<!-- ComboBox and ListView width -->
</Grid.ColumnDefinitions>
<Label Content="Destination Views: " Margin="10 0 0 0" VerticalAlignment="Center"/>
<ScrollViewer x:Name="sv_DestinationViews" Grid.Column="1" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" CanContentScroll="True">
<ListView x:Name="lv_DestinationViews" SelectionMode="Extended" PreviewMouseWheel="ListBox_PreviewMouseWheel" MinHeight="200">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}" VerticalAlignment="Center" Margin="0,0,5,0"/>
<TextBlock Text="{Binding}" VerticalAlignment="Center" IsHitTestVisible="False"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
</GroupBox>
<!-- OK and Cancel buttons -->
<StackPanel Grid.Row="2" Margin="5,5,5,5" VerticalAlignment="Bottom" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="bt_Ok" Content="OK" Width="100" Click="bt_Ok_Click"/>
<Button x:Name="bt_Cancel" Content="Cancel" Width="100" Margin="5 0 0 0" Click="bt_Cancel_Click"/>
</StackPanel>
</Grid>
</Window>
```