Uwp图像缩放

时间:2018-04-20 09:15:34

标签: xaml uwp

我正在尝试使用RenderTransform缩放gridview项目中的图像。缩放 成功执行但缩放图像位于gridview项目后面。如何把它带到前面。

<VisualState x:Name="PointerOver">
 <Storyboard  >
  <DoubleAnimation Duration="0" Storyboard.TargetName="BorderRectangle" 
   Storyboard.TargetProperty="Opacity" To="1" />
    <ObjectAnimationUsingKeyFrames  
      Storyboard.TargetName="contentborderscale" 
      Storyboard.TargetProperty="ScaleY" >
       <DiscreteObjectKeyFrame KeyTime="0" Value="2" />
   </ObjectAnimationUsingKeyFrames>
   <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentborderscale" 
    Storyboard.TargetProperty="ScaleX">
     <DiscreteObjectKeyFrame  KeyTime="0" Value="2"  />
   </ObjectAnimationUsingKeyFrames>
   <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
 </Storyboard>
</VisualState>

1 个答案:

答案 0 :(得分:0)

简而言之,您希望缩放GridViewItem的容器。

我查看GridView selectedItem Popup (Method 2)

的答案
  

方法2:指针悬停

     

XAML部分

<GridView Height="200">
    <GridView.ItemTemplate>
        <DataTemplate x:DataType="local:ItemSource">
            <Grid Width="100" Height="100" PointerEntered="GridView_PointerEntered" PointerExited="GridView_PointerExited">
                <!-- Content -->
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>
     

C#Part

FrameworkElement lastPopUpElement = null;
private void GridView_PointerEntered(object sender, PointerRoutedEventArgs e)
{
    lastPopUpElement = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(sender as FrameworkElement) as FrameworkElement) as FrameworkElement;
    Canvas.SetZIndex(lastPopUpElement, 1);
    lastPopUpElement.Scale(scaleX: 1.5f, scaleY: 1.5f, centerX: 50, centerY: 50, easingType: EasingType.Sine).Start();
}

private void GridView_PointerExited(object sender, PointerRoutedEventArgs e)
{
    if (lastPopUpElement != null)
    {
        Canvas.SetZIndex(lastPopUpElement, 0);
        lastPopUpElement.Scale(centerX: 50, centerY: 50, easingType: EasingType.Sine).Start();
    }
}
     

示例输出

     

enter image description here