更改 UWP FlipView
Change UWP FlipView
是否可以在UWP Flipview控件中更改图片时更改动画效果?与其滑入,我更喜欢交叉淡入淡出效果。
我没看到办法,但我想确认一下。感谢您的帮助。
谢谢。
没有仔细查看,但在默认模板 (https://msdn.microsoft.com/en-us/library/windows/apps/mt299124.aspx) 中有一个用于项目的水平堆栈面板和一个滚动查看器,所以我真的不知道这样做的方法。
就我个人而言,我认为编写一个自定义控件会更容易,当用户按下按钮或其他东西时,它会淡入淡出集合中的项目
您应该能够在隐藏代码中手动覆盖动画。首先,使用 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>
然后,运行 代码隐藏中的故事板:
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();
}
是否可以在UWP Flipview控件中更改图片时更改动画效果?与其滑入,我更喜欢交叉淡入淡出效果。
我没看到办法,但我想确认一下。感谢您的帮助。
谢谢。
没有仔细查看,但在默认模板 (https://msdn.microsoft.com/en-us/library/windows/apps/mt299124.aspx) 中有一个用于项目的水平堆栈面板和一个滚动查看器,所以我真的不知道这样做的方法。
就我个人而言,我认为编写一个自定义控件会更容易,当用户按下按钮或其他东西时,它会淡入淡出集合中的项目
您应该能够在隐藏代码中手动覆盖动画。首先,使用 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>
然后,运行 代码隐藏中的故事板:
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();
}