3

I am developing Windows Store App, and I have such XAML code:

<Popup x:Name="Panel3" IsOpen="False" Grid.ColumnSpan="18" Grid.Column="13" Grid.Row="4" Grid.RowSpan="31">
    <StackPanel>
        <Rectangle  Width="765" Height="10" />
        <ListView x:Name="Person" Grid.ColumnSpan="18" Grid.Column="13" HorizontalAlignment="Left" Height="643" Grid.Row="4" Grid.RowSpan="31" VerticalAlignment="Top" Width="765" >
            <ListView.Background>
                <SolidColorBrush Color="#FF665920" Opacity="0.85"/>
            </ListView.Background>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding name}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>
</Popup>

I want to make item selection on listview disabled. So it is for view only, users cannot select/click anything inside listview. How can i make that happen? My regards...

P.S. I added IsItemClickEnabled="False" to listview line:

<ListView x:Name="Person" Grid.ColumnSpan="18" Grid.Column="13" HorizontalAlignment="Left" Height="643" Grid.Row="4" Grid.RowSpan="31" VerticalAlignment="Top" Width="765" IsItemClickEnabled="False">

But it did not change anything, still clickable.

Alasse
  • 361
  • 2
  • 9
  • 17

2 Answers2

11

You need set the SelectionMode property to None to disable the item selection of a ListView:

<ListView x:Name="Person" SelectionMode="None" ... />

additionally you may still need the IsItemClickEnabled="False" depending on your needs.

nemesv
  • 138,284
  • 16
  • 416
  • 359
  • @nemesv Thanks, doing this stops selection of the item, but I still get the animation when I click an item. Do you know of a way to stop the animation also? – Percy Apr 13 '16 at 10:29
0

In newer versions of Windows 10 that have a highlighted list view item animation

I've found you need to modify the visual state of the ListViewItem along with setting the SelectionMode="None" and IsItemClickEnabled="False" if needed, as nemesv said in his answer.

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <!-- here we are clearing the state behavior, 
                                     thus disabling the clickability of the ListViewItem -->
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver" />
                                <VisualState x:Name="Pressed" />
                             </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <ContentPresenter x:Name="ListViewItemContent" />
                        </Grid>
                   </Grid>
                </ControlTemplate>
            </Setter.Value>
       </Setter>
    </Style>
</ListView.ItemContainerStyle>
visc
  • 4,794
  • 6
  • 32
  • 58