【问题标题】:ListViewItem style doesn't work correctlyListViewItem 样式无法正常工作
【发布时间】:2016-07-08 14:41:16
【问题描述】:

我今天有一个奇怪的问题。我有以下列表视图:

<ListView ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                          IsItemClickEnabled="True"
                          SelectionMode="Single"
                          x:Name="listviewZoomedIn"
                          ItemContainerStyle="{StaticResource ListViewCustomItemStyle}"/>

而名为“ListViewCustomItemStyle”的ItemContainerStyle如下:

<Style TargetType="ListViewItem" x:Key="ListViewTransmitterItemStyle">
    <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
      ContentTransitions="{TemplateBinding ContentTransitions}"
      SelectionCheckMarkVisualEnabled="True"
      CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
      CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
      DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
      DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
      FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
      FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
      PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
      PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
      PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
      SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
      SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
      SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
      PressedBackground="Orange"
      SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
      DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
      DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
      ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
      ContentMargin="{TemplateBinding Padding}"
      CheckMode="Inline"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

在这种样式中,我只是更改了 PressedBackground 颜色。 这仅适用于第一次单击项目。然后,按下的背景是透明的。

【问题讨论】:

    标签: listview uwp listviewitem


    【解决方案1】:

    在您更改为OrangePressedBackground 属性下方是SelectedPressedBackground 属性。 这定义了选定项目的按下状态颜色。将其更改为 Orange 或您需要的任何颜色,它应该可以工作。

    【讨论】:

    • 逻辑...谢谢你
    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2021-04-08
    相关资源
    最近更新 更多