我有一个列表视图,但我的列表视图有多个选择,即使选择模式是单一的?我已经张贴的属性设置列表视图和itemcontainerstyle。
<ListView SelectionMode="Single" Tapped="UIElementTapped"
ItemsSource="{Binding Path=ListTimeFrame}"
SelectedItem="{Binding Path=SelectedTimeFrame, Mode=TwoWay}"
ItemContainerStyle="{StaticResource TimeFrameListViewItemContainerStyle}"
Padding="0"
Margin="0">
和itemcontainer样式,如下所示
<Style x:Key="TimeFrameListViewItemContainerStyle" TargetType="ListViewItem">
<Setter Property="Padding" Value="4,1" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity" Duration="0" To="1" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{StaticResource DefaultTextBlueColor}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="" FontFamily="Segoe UI Symbol"
Foreground="{StaticResource DefaultTextBlueColor}" x:Name="SelectingGlyph"
Opacity="0" FontSize="20" LineStackingStrategy="BlockLineHeight" />
<ContentPresenter x:Name="contentPresenter" Grid.Column="1"
ContentTransitions="{TemplateBinding ContentTransitions}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
1条答案
按热度按时间jgwigjjp1#
列表视图有多个选择,即使设置选择模式单一
这是因为您缺少
Normal
视觉状态。您在ListViewItem
样式中设置了选定的视觉状态,但没有给予Normal
状态。ListViewItem
中的未选定状态是Normal
状态。因此,在SelectionStates
视觉状态组中添加以下视觉状态。所有可视状态代码如下所示: