Reputation: 361
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.
Upvotes: 3
Views: 4385
Reputation: 4959
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>
Upvotes: 0
Reputation: 139758
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.
Upvotes: 11