BenBtg
BenBtg

Reputation: 836

Make a Windows 8 ListView Items only selectable from code

I have a list view with single selection enabled but I only want the selection to be done from code not via user interaction. The reason is I am using the the Vistual State Manager Selection state groups as an easy way to handle rendering and animating an 'active' state transition. This all works great with a nice transition between each item except I don't want the user to be able to set the 'active' item.

I have tried a few obvious things like overrideing the OnTapped Routed event and setting the Handled state to true but the item still gets selected.

Upvotes: 0

Views: 724

Answers (1)

Seb Boulet
Seb Boulet

Reputation: 981

If you want your user to still be able to scroll but not be able to select, a good bet is to combine a ScrollView with a ListView that has IsHitTestVisible set to False:

<ScrollViewer Width="100" Height="100"
    HorizontalAlignment="Left" VerticalAlignment="Top"
    VerticalScrollBarVisibility="Auto">

    <ListView Name="Foo" BorderThickness="0" IsHitTestVisible="False">
        <System:String>Item 1</System:String>
        <System:String>Item 2</System:String>
        <System:String>Item 3</System:String>
        etc...
    </ListView>
</ScrollViewer>

Note that the user will be able to change the selection of the ListView with the keyboard if they receive focus on the ListView, so make sure this cannot happen.

Upvotes: 2

Related Questions