Search code examples
xamlwindows-store-apps

How to enable both selection and item click in a Windows Store application


I have a ListView like this:

<ListView SelectionMode="Single" IsItemClickEnabled="True" ItemsSource="..." ItemClick="listView_ItemClick">
    ...
</ListView>

When this listview is displayed, the first item is selected.

Clicking on items trigger listView_ItemClick. Everything is fine to this point.

Problem is, the first item is always stay selected. Even when I click on other items, they trigger click event, but they do not get selected. How can I get items both trigger click event and get selected when the user clicks or touches them?


Solution

  • As per MSDN:

    If you set the IsItemClickEnabled property to true, you must set the SelectionMode property to ListViewSelectionMode.None. Handle the ItemClick event to respond to the user interaction.

    I'm affriad it's one or the other. But why not use SelectionMode="Single", and subscribe to the selection changed event?