ListViewItem悬停效果

时间:2016-02-09 12:20:25

标签: c# listview uwp

如何在Windows 10 Universal News应用中为Listview项目实现悬停效果?触摸项目或使用鼠标悬停时,会有一个缩放效果,该项目带有灰色边框。 你可以在图片中看到。

Normal Style

Hover Style

编辑: 我试图像这样从ListViewItem更改FocusBorderBrush。

将此添加到app.xaml

    <Style TargetType="ListViewItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <ListViewItemPresenter 
                                       FocusBorderBrush="{ThemeResource GreenBackgroundThemeBrush}"
                                       />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <SolidColorBrush x:Key="GreenBackgroundThemeBrush" Color="Green" />

这是我的列表视图:

<ListView ItemsSource="{Binding myItems}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBlock Text="{Binding id}"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>     
    </ListView>

但是,当项目具有焦点时,这仅更改边框颜色。

现在看起来像这样:

enter image description here

有没有办法做新闻应用程序之类的东西,而不仅仅是关注项目?

1 个答案:

答案 0 :(得分:2)

将以下内容添加到App文件中,然后根据需要进行编辑。这是ListView的默认样式,你不需要所有它,但我只是认为最好向你展示可以改变的一切,你需要的部分是FocusBorderBrush,以及指向属性的指针。小心。

<Style TargetType="ListViewItem">
        <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
        <Setter Property="TabNavigation" Value="Local" />
        <Setter Property="IsHoldingEnabled" Value="True" />
        <Setter Property="Padding" Value="12,0,12,0" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" />
        <Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                    <ListViewItemPresenter HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                           CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                                           CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                                           CheckMode="Inline"
                                           ContentMargin="{TemplateBinding Padding}"
                                           ContentTransitions="{TemplateBinding ContentTransitions}"
                                           DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
                                           DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
                                           DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
                                           DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
                                           FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
                                           FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
                                           PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
                                           PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
                                           PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                                           PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
                                           ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
                                           SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
                                           SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                                           SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
                                           SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
                                           SelectionCheckMarkVisualEnabled="True" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>