2014-11-15 3 views
1

Как сделать деактивировать анимацию щелчка GridViewItem (показано ниже), при щелчке правой кнопкой мыши a GridViewItem?Как отключить анимацию GridViewItem?

GridViewItem-click animation

Edit:
код после того, как предложение Нейта (не работает). Я добавил VisualStates, но я все еще вижу анимацию. Однако выбранные элементы больше не имеют синей границы, так как я добавил элемент VisualStateGroup (что меня не волнует, но код имеет некоторые эффекты).

<Page 
    x:Name="pageRoot" 
    x:Class="MovieLibrary.VideoPage" 
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:MovieLibrary" 
    xmlns:common="using:MovieLibrary.Common" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" Loaded="pageRoot_Loaded"> 

    <Page.Resources> 
     <local:SetPercentageConverter x:Key="SetPercentageConverter"/> 
     <!-- TODO: Delete this line if the key AppName is declared in App.xaml --> 
     <x:String x:Key="AppName">Hello, video!</x:String> 

     <Style x:Key="GridViewItemStyle" TargetType="GridViewItem"> 
      <Setter Property="Margin" Value="0"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="GridViewItem"> 
         <GridViewItemPresenter x:Name="gridViewItemPresenter" Padding="0" ContentMargin="0"> 
           <VisualStateGroup x:Name="CommonStates"> 
            <VisualState x:Name="Pressed"><Storyboard/></VisualState> 
            <VisualState x:Name="PointerOverPressed"><Storyboard/></VisualState> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
         </GridViewItemPresenter> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

    </Page.Resources> 

    <Page.TopAppBar> 
     <CommandBar x:Name="commandBar"> 
      <AppBarButton x:Name="SyncMovieLibraryButton" Icon="SyncFolder" Label="Sync Movie Library" Click="SyncMovieLibraryButton_Click"/> 
      <AppBarButton x:Name="SetMovieLibraryButton" Icon="Folder" Label="Set Movie Library" Click="SetMovieLibraryButton_Click"/> 
     </CommandBar> 
    </Page.TopAppBar> 

    <GridView x:Name="videoGridView" ItemsSource="{Binding Movies}" ItemContainerStyle="{StaticResource GridViewItemStyle}" Padding="0" RightTapped="videoGridView_RightTapped"> 
     <GridView.ItemTemplate> 
      <DataTemplate> 
       <Image Source="{Binding PosterPath}" Loaded="Image_Loaded" Stretch="UniformToFill" RightTapped="Image_RightTapped" /> 
      </DataTemplate> 
     </GridView.ItemTemplate> 
    </GridView> 
</Page> 
+0

В [GridViewItem стилях и шаблонах по умолчанию] (http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709915.aspx), в частности нижний, вы заметите, что там является 'StoryBoard' для состояния' Pressed', которое включает 'PointerDownThemeAnimation'. Скопируйте стиль, удалите «StoryBoard» (или просто анимацию), должно быть хорошо, чтобы идти. –

+0

Спасибо за ваш ответ, но: Нет, не работает. Не могли бы вы проверить, допустил ли я ошибку? – Daniel

+0

Похоже, что «PointerOverPressed» может иметь аналогичную анимацию. Попробуйте переписать это тоже. –

ответ

1

Для того, чтобы сделать это только для правой кнопки мыши, вы, вероятно, придется сделать пользовательский элемент управления, который не вызывает указатель нажимаются изменений состояния на правой кнопке мыши, но делаешь на левой кнопку мыши.

Следующая часть для лево- и правой кнопкой мыши:

Есть две вещи, чтобы попробовать, основываясь на текущем Xaml.

В GridViewItem default styles and templates есть два шаблона контента, один из которых использует GridViewItemPresenter, а другой - нет.

Во-первых, попробуйте использовать стиль GridViewItemPresenter, но перепишите ContentTransitions с новым TransitionCollection.

<!-- Default style for Windows.UI.Xaml.Controls.GridViewItem --> 
<Style TargetType="GridViewItem"> 
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> 
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="TabNavigation" Value="Local"/> 
    <Setter Property="IsHoldingEnabled" Value="True"/> 
    <Setter Property="Margin" Value="0,0,2,2"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="GridViewItem"> 
       <GridViewItemPresenter 
        Padding="{TemplateBinding Padding}" 
        SelectionCheckMarkVisualEnabled="True" 
        CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" 
        CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" 
        CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" 
        DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" 
        DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" 
        FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" 
        PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
        PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" 
        SelectedBorderThickness="{ThemeResource GridViewItemCompactSelectedBorderThemeThickness}" 
        SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" 
        SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" 
        SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" 
        SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" 
        DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" 
        DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" 
        ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" 
        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
        PointerOverBackgroundMargin="1" 
        ContentMargin="4" > 
        <GridViewItemPresenter.ContentTransitions> 
         <TransitionCollection/> 
        </GridViewItemPresenter.ContentTransitions> 
       </GridViewItemPresenter> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

Если это все еще не работает, используйте стиль ниже того, который находится на той же странице. Слишком долго, чтобы его полностью разместили, поэтому я только что добавил фиксированный VisualStateGroup для CommonStates. Если вы перейдете к тому месту, которое я связал выше, выделите раздел внизу и скопируйте его, затем сверните и перезапишите блок CommonStates VisualStateGroup, он должен работать.

<VisualStateGroup x:Name="CommonStates"> 
    <VisualState x:Name="Normal"/> 
    <VisualState x:Name="PointerOver"> 
     <Storyboard> 
      <DoubleAnimation Storyboard.TargetName="PointerOverBorder" 
          Storyboard.TargetProperty="Opacity" 
          Duration="0" 
          To="1" /> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectionBackground" 
              Storyboard.TargetProperty="Fill"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectedBorder" 
              Storyboard.TargetProperty="Stroke"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectedEarmark" 
              Storyboard.TargetProperty="Fill"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
     </Storyboard> 
    </VisualState> 
    <VisualState x:Name="Pressed"> 
     <Storyboard/> 
    </VisualState> 
    <VisualState x:Name="PointerOverPressed"> 
     <Storyboard> 
      <DoubleAnimation Storyboard.TargetName="PointerOverBorder" 
          Storyboard.TargetProperty="Opacity" 
          Duration="0" 
          To="1" /> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectionBackground" 
              Storyboard.TargetProperty="Fill"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectedBorder" 
              Storyboard.TargetProperty="Stroke"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectedEarmark" 
              Storyboard.TargetProperty="Fill"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
     </Storyboard> 
    </VisualState> 
    <VisualState x:Name="Disabled"> 
     <Storyboard> 
      <DoubleAnimation Storyboard.TargetName="contentPresenter" 
          Storyboard.TargetProperty="Opacity" 
          Duration="0" 
          To="{ThemeResource ListViewItemDisabledThemeOpacity}" /> 
     </Storyboard> 
    </VisualState> 
</VisualStateGroup> 

Надеюсь, что это поможет и счастливое кодирование!

+0

Отлично, это помогает. Теперь анимация отключена. Однако также для щелчка левой кнопкой мыши. Пока я не нашел решение этого, я не могу отметить это как ответ, но как полезный. Если я найду решение, добавлю его к вашему ответу и отметьте его. :) Спасибо! – Daniel

+0

Чтобы сделать это только для щелчка правой кнопкой мыши, вам, скорее всего, придется создать настраиваемый элемент управления, который не вызывает нажатие на нажатие клавиши нажатием на клик правой кнопкой мыши, но на левом клике. –

Смежные вопросы