我想从屏幕右侧打开 Popup 作为幻灯片动画,如下图所示
弹出窗口放置在屏幕的右侧,现在弹出窗口像往常一样打开,没有任何动画。请帮忙。提前致谢
我已经按照我的逻辑完成了,绝对不是一个完美的答案,但它正在工作。我所做的是 1) 将弹出/网格控件放在屏幕右侧之外,我必须从那里打开/关闭带有动画的弹出窗口
因此,当我想打开我的弹出窗口时,我正在向部分 (2) 添加厚度动画和弹出/网格动画,如图所示,虽然需要再次删除弹出窗口/网格,但我正在应用厚度动画,以便移动我的弹出窗口/网格到部分(1),如图所示这是我的代码。
//for opening Popup
myPopupGrid.Margin = new Thickness(0, 0, -myPopupGrid.Width, 0);
ThicknessAnimation thicknessAnimation = new ThicknessAnimation();
thicknessAnimation .From = myPopupGrid.Margin;
thicknessAnimation .To = new Thickness(0, 0, 0, 0);
thicknessAnimation .Duration = new Duration(TimeSpan.FromSeconds(0.5));
myPopupGrid.BeginAnimation(Grid.MarginProperty, thicknessAnimation );
thicknessAnimation .Completed += delegate { myPopupGrid.Visibility = Visibility.Visible; };
//for closing Popup
myPopupGrid.Margin = new Thickness(0, 0, 0, 0);
ThicknessAnimation thicknessAnimation = new ThicknessAnimation();
thicknessAnimation .From = myPopupGrid.Margin;
thicknessAnimation .To = new Thickness(0, 0, -myPopupGrid.Width, 0);
thicknessAnimation .Duration = new Duration(TimeSpan.FromSeconds(0.5));
myPopupGrid.BeginAnimation(Grid.MarginProperty, thicknessAnimation );
thicknessAnimation .Completed += delegate { myPopupGrid.Visibility = Visibility.Hidden; };
//Here point of notice is I am changing Thickness in both cases
//From
new Thickness(0, 0, -myPopupGrid.Width, 0)
//To
new Thickness(0, 0, 0, 0);
反之亦然,这会导致我的弹出窗口将他的位置重置为往返,就是这样