我正在使用WPF编写Windows 8平板电脑应用程序并在屏幕上显示ListView控件。
列表视图包含多个覆盖1页以上的行,因此启用了垂直滚动。
当我触摸屏幕时,当我向上和向下滚动时,会出现一个淡蓝色选择器并停留在屏幕中间(但是以深蓝色突出显示的所选项目不会改变)。我猜这是鼠标效应,因为当我使用鼠标时会出现相同的效果。
我也为项目集合使用DataTemplate。
我怎样才能让苍白的蓝色鼠标超过效果?
这是我的ListView的XAML
<ListView Grid.Row="1"
Margin="10"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource MyData}}"
ItemTemplate="{StaticResource MyItemTemplate}"
ScrollViewer.CanContentScroll="False"
ScrollViewer.PanningMode="VerticalOnly"
ScrollViewer.PanningRatio="0.5">
</ListView>
这是我的项目模板:
<DataTemplate x:Key="MyItemTemplate">
<Grid Margin="10,5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Border BorderBrush="Gray"
BorderThickness="1"
Grid.RowSpan="2"
CornerRadius="5" />
<TextBlock Text="{Binding Name}"
FontSize="20"
VerticalAlignment="Center"
Grid.Row="0"
Margin="10" />
<Border Background="#FFB9B9B9"
Grid.Row="1"
CornerRadius="5"
Margin="10,0,10,4">
<StackPanel HorizontalAlignment="Stretch"
Orientation="Horizontal"
Grid.Row="1">
<TextBlock VerticalAlignment="Center"
Text="Status: "
Margin="5,5,0,5" />
<TextBlock VerticalAlignment="Center"
Text="{Binding CompletionStatus}" />
<TextBlock VerticalAlignment="Center"
Text="% complete, " />
<TextBlock VerticalAlignment="Center"
Text="Upload status: " />
<TextBlock VerticalAlignment="Center"
Text="{Binding UploadStatus}" />
<TextBlock VerticalAlignment="Center"
Text="last Modified: " />
<TextBlock VerticalAlignment="Center"
Text="{Binding LastModified}" />
</StackPanel>
</Border>
</Grid>
</DataTemplate>
我正在使用Visual studio / Blend 2012。
提前致谢
答案 0 :(得分:15)
修改强>
我能让这个工作的唯一方法是重新定义ListViewItem
ControlTemplate
。尝试下面的代码,看看它是否能解决您的问题:
ListViewItem
Style
:
<Style x:Key="LvItemStyle" TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="border" Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="border"
Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="LightBlue" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="border"
Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="SkyBlue" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<强> ListView
强>
<Grid Background="DarkGray">
<ListView Grid.Row="1"
Margin="10"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding MyItems}"
ItemTemplate="{StaticResource LvDataTemplate}"
ItemContainerStyle="{StaticResource LvItemStyle}"
ScrollViewer.CanContentScroll="False"
ScrollViewer.PanningMode="VerticalOnly"
ScrollViewer.PanningRatio="0.5">
</ListView>
</Grid>
出于演示目的,我已对Selected
VisualStates
的颜色进行了硬编码。理想情况下,您可以从资源文件中获取这些内容。
答案 1 :(得分:1)
对我而言,它运作良好,如下:
<button type="button"
onclick="document.getElementById('msg').innerHTML = 'Gone!'">
Click Me!</button> <button type="button"
onclick="document.getElementById('msg').innerHTML = 'Back again!'">
Bring me back!</button>