Roberto Salemi

Roberto Salemi

  • NA
  • 146
  • 142.1k

[WPF] ListView: SelectedItems returns always one element

Apr 28 2015 12:06 PM

Hi,

I using ListView:

<ListView x:Name="chkListViewSampleStatus" HorizontalAlignment="Left" VerticalAlignment="Top"DataContext="{StaticResource DomainDataViewModel}" ItemsSource="{Binding SampleStatus}" IsSynchronizedWithCurrentItem="True" Width="727" Height="50">

<ListView.ItemsPanel>

<ItemsPanelTemplate>

<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"

  ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"

  MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"

  ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />

</ItemsPanelTemplate>

</ListView.ItemsPanel>

<ListView.View>

<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">

<GridView.Columns>

<GridViewColumn Width="20">

<GridViewColumn.CellTemplate>

<DataTemplate>

<CheckBox Tag="{Binding Name}" HorizontalContentAlignment="Stretch" Margin="-5" Padding="-5"/>

</DataTemplate>

</GridViewColumn.CellTemplate>

</GridViewColumn>

<GridViewColumn DisplayMemberBinding="{Binding ValueDescription}" Width="110" />

</GridView.Columns>

</GridView>

</ListView.View>

</ListView>

I see 8 elements (checkbox + label), I select 2 or more element, but in code behind if I would get selected item with:

chkListViewSampleStatus.SelectedItems

It returns always one element.

Why?

Thanks.


Answers (4)