更改UWP FlipView

时间:2017-03-22 18:09:40

标签: animation uwp uwp-xaml flipview

在UWP Flipview控件中更改图像时是否可以更改动画效果?而不是滑入,我宁愿一个交叉淡入淡出效果。

我没有办法做到这一点,但我想确认一下。任何帮助表示赞赏。

感谢。

2 个答案:

答案 0 :(得分:1)

您应该可以在后面的代码中手动覆盖动画。首先,使用UseTouchAnimationsForAllNavigation =" False"禁用内置动画。

    <FlipView x:Name="FlipView" UseTouchAnimationsForAllNavigation="False" SelectionChanged="Selector_OnSelectionChanged" >
        <FlipView.Items>
            <Grid Background="Red"></Grid>
            <Grid Background="Blue"></Grid>
            <Grid Background="Green"></Grid>
        </FlipView.Items>
    </FlipView>

然后,在codebehind中运行故事板:

    private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count <= 0) return;
        if (e.RemovedItems.Count <= 0) return;

        var newSelectedItem = FlipView.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as FlipViewItem;
        var previousSelectedItem = FlipView.ItemContainerGenerator.ContainerFromItem(e.RemovedItems[0]) as FlipViewItem;

        if (newSelectedItem == null) return;
        if (previousSelectedItem == null) return;

        var duration = new Duration(TimeSpan.FromMilliseconds(500));

        var hideAnimation = new DoubleAnimation
        {
            From = 1.0,
            To = 0.0,
            AutoReverse = false,
            Duration = duration
        };

        var hideSb = new Storyboard();
        hideSb.Children.Add(hideAnimation);
        Storyboard.SetTargetProperty(hideSb, "Opacity");
        Storyboard.SetTarget(hideSb, previousSelectedItem);

        hideSb.Begin();

        var showAnimation = new DoubleAnimation
        {
            From = 0.0,
            To = 1.0,
            AutoReverse = false,
            Duration = duration
        };

        var showSb = new Storyboard();
        showSb.Children.Add(showAnimation);
        Storyboard.SetTargetProperty(showSb, "Opacity");
        Storyboard.SetTarget(showSb, newSelectedItem);

        showSb.Begin();
    }

答案 1 :(得分:0)

没有彻底的外观,但在默认模板(https://msdn.microsoft.com/en-us/library/windows/apps/mt299124.aspx)中有一个水平堆栈面板和一个滚动查看器,所以我真的没办法做到这一点。

就我个人而言,当用户按下按钮或其他东西时,我认为编写一个自定义控件可以更轻松地逐渐淡出集合中的项目