在UWP GridView项

时间:2017-01-09 05:36:29

标签: xaml uwp windows-10-universal uwp-xaml

当我将鼠标悬停在GridView中的某个项目上时,我希望有一些简单的效果,例如缩放或暗淡/淡化gridview项目。我怎样才能做到这一点。我想要实现的一些例子如下。

示例1(比例):

`https://codepen.io/wifeo/pen/qzwkb`

示例2(淡入淡出):

`http://codepen.io/chrisgrabinski/full/gpqtc/`

1 个答案:

答案 0 :(得分:1)

  

示例1(比例) - 将鼠标悬停在GridView中的项目上

第一个问题应该在SO上得到解答:In UWP, how can I scale an item on GridView when item is selected根据您的要求,您只需要使用PointerEntered和PointerExited事件来获取它。

  

示例2(淡入淡出)

第二个问题,您需要知道Fade animation我已经制作了一个简单的代码示例供您参考。

<GridView x:Name="gv">
        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited">
                    <Grid.Resources>
                        <Storyboard x:Name="EnterStoryboard">
                            <FadeOutThemeAnimation Storyboard.TargetName="myRectangle" />
                        </Storyboard>
                        <Storyboard x:Name="ExitStoryboard">
                            <FadeInThemeAnimation Storyboard.TargetName="myRectangle" />
                        </Storyboard>
                    </Grid.Resources>
                    <Rectangle Fill="Blue" x:Name="myRectangle" Width="100" Height="100"></Rectangle>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        Storyboard sb = ((Grid)sender).Resources["EnterStoryboard"] as Storyboard;
        sb.Begin();
    }

    private void Grid_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        Storyboard sb = ((Grid)sender).Resources["ExitStoryboard"] as Storyboard;
        sb.Begin();
    }