【发布时间】:2016-05-13 16:20:43
【问题描述】:
我在 Windows 通用项目中有一个 ListView 对象。我想为 Selected 和 Unselected 状态设置两个Visual States。我从 MSDN 复制了代码:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver">
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected">
<Storyboard>
<ColorAnimation Duration="0:0:.1" To="{StaticResource HighlightColor}" Storyboard.TargetName="brd" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<ColorAnimation.EasingFunction>
<PowerEase Power="2" />
</ColorAnimation.EasingFunction>
</ColorAnimation>
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Duration="0:0:.1" To="{StaticResource FlowBlue}" Storyboard.TargetName="brd" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<ColorAnimation.EasingFunction>
<PowerEase Power="2" />
</ColorAnimation.EasingFunction>
</ColorAnimation>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border Tapped="brd_Tapped" GotFocus="brd_GotFocus" Width="100" Height="85" Background="{StaticResource HighlightColorBrush}" BorderThickness="0" Name="brd" Tag="" Margin="5">
<Grid Name="grd" Tag="">
<TextBlock FontWeight="Bold" VerticalAlignment="Bottom" FontSize="18" HorizontalAlignment="Right" Foreground="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
<control:TextBoxEx LostFocus="TextBoxEx_LostFocus" IsHitTestVisible="True" DoubleTapped="TextBoxEx_DoubleTapped" Background="Transparent" Text="{Binding Path=ItemName, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Width="100" />
</Grid>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
当我运行并单击一个项目时,将调用 Selected 状态。但是当我点击另一个项目时,它也会设置 Selected 状态。但第一项并没有取消选择。我尝试将 SelectionMode 设置为 Single,但没有帮助。 我该怎么做才能取消选择该项目?
【问题讨论】:
-
如果我没记错的话,我认为 SelectionMode 用于 ListBox 而 MultiSelect="False" 将用于 ListView。
-
@ChrisW:我尝试设置 MultiSelect,但 Windows Universal 中 ListView 的属性不再存在。我尝试了所有的选择模式,但没有用。
-
你解决了吗?目前正在拉扯我的头发-_-