我不知道如何禁用自动滚动操作,但我对该代码有一个快速修复:
在班上ItemFlyInAndOutAnimations
添加字段
private FrameworkElement _element; //let's consider the line is 266
在进行public void ItemFlyIn()
更改:
public void ItemFlyIn()
{
if (_popupCanvas.Children.Count != 2)
return;
_popup.IsOpen = true;
_backgroundMask.Opacity = 0.0;
Image animatedImage = _popupCanvas.Children[1] as Image;
var sb = new Storyboard();
var rootFame = Application.Current.RootVisual as FrameworkElement; //new line
var targetElementPosition = _element.GetRelativePosition(rootFame); //new line
// animate the X position
var db = CreateDoubleAnimation(targetElementPosition.X - 100, targetElementPosition.X,
new SineEase(),
_targetElementClone, Canvas.LeftProperty, _flyInSpeed); //reference changed!
sb.Children.Add(db);
// animate the Y position
db = CreateDoubleAnimation(targetElementPosition.Y - 50, targetElementPosition.Y,
new SineEase(),
_targetElementClone, Canvas.TopProperty, _flyInSpeed); //reference changed!
sb.Children.Add(db);
//other code is the same
在public void ItemFlyOut(FrameworkElement element, Action action)
在这条线之后
_targetElementPosition = element.GetRelativePosition(rootElement);
添加这个:
_element = element;
我做了什么:
在这段代码中,我保存了对动画 UI 元素的引用,并更新了它在背面动画上的位置。
你最好测试一下这段代码,但它似乎没问题。