如何在 Win10 Universal 应用程序中禁用 GridView/ListView 上的倾斜动画? [英] How can I disable tilt animation on GridView/ListView in Win10 Universal app?

查看:13
本文介绍了如何在 Win10 Universal 应用程序中禁用 GridView/ListView 上的倾斜动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去我可以通过编辑项目容器样式和删除故事板动画来取消 GridView/ListView 上的倾斜效果.

It used to be I could cancel the tilt effect on GridView/ListView by editing the item container style and removing the storyboard animations.

但是,当我现在在 Win10 Universal 应用程序上编辑模板时,我看不到任何故事板.在哪里可以取消动画?

However, when I edit the templates now on Win10 Universal apps, I am not seeing any of the storyboards. Where can I cancel the animation at?

这是为我生成的样式(使用时不会禁用动画):

Here's the style that's generated for me (and when used, does not disable animation):

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

推荐答案

一种方法是通过插入另一个 Control 来阻止来自 ListViewItem 的交互.

One way is to block the interaction from the ListViewItem by inserting another Control.

例如,将 ItemTemplate 内的内容用 Button 包裹起来,样式如下几乎为空.

For example, wrap the content inside the ItemTemplate with a Button with the following almost empty style.

<Style x:Key="EmptyButtonStyle" TargetType="Button">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="VerticalAlignment" Value="Stretch" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="UseSystemFocusVisuals" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
                    <ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<DataTemplate x:Name="ListViewItemTemplate">
    <Button Style="{StaticResource EmptyButtonStyle}">
        <!-- Put your original stuff here -->
    </Button>
</DataTemplate>

这篇关于如何在 Win10 Universal 应用程序中禁用 GridView/ListView 上的倾斜动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆