Xaml Listview禁用项目单击
我正在开发Windows应用商店应用程序,我有这样的XAML代码:Xaml Listview禁用项目单击,xaml,windows-store-apps,Xaml,Windows Store Apps,我正在开发Windows应用商店应用程序,我有这样的XAML代码: <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:Nam
<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>
我想禁用listview上的项目选择。因此,它仅用于查看,用户无法选择/单击listview中的任何内容。我怎样才能做到这一点?我的问候
附言。
我将IsItemClickEnabled=“False”添加到listview行:
<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">
但它没有改变任何东西,仍然可以点击 您需要将属性设置为None
,以禁用列表视图的项目选择:
<ListView x:Name="Person" SelectionMode="None" ... />
此外,根据您的需要,您可能仍然需要IsItemClickEnabled=“False”
。我发现您需要修改列表视图项的可视状态,同时设置选择模式=“None”
和IsItemClickEnabled=“False”
,如nemesv在回答中所述
<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>
/VisualStateGroup>
@nemesv谢谢,这样做会停止对项目的选择,但我在单击项目时仍会获得动画。你知道停止动画的方法吗?