我已經創建了一個自定義的控件,它從頁面繼承,爲NavigatingFrom事件設置動畫效果。但是,我似乎無法播放實際的動畫。這是我的全部AltPage.cs代碼:自定義Page控件中的動畫組合?
public class AltPage : Page
{
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
//Set up the composition animation
var _compositor = new Compositor();
var _targetVisual = ElementCompositionPreview.GetElementVisual(this);
var animation = _compositor.CreateScalarKeyFrameAnimation();
animation.Duration = new TimeSpan(0, 0, 0, 0, 300);
animation.InsertKeyFrame(1.0f, 0f);
_targetVisual.StartAnimation("Opacity", animation);
//Give some time for the animation to start
Task.Delay(18);
//Get the page to initialize while the animation is playing
base.OnNavigatingFrom(e);
}
}
當我運行的代碼,行_targetVisual.StartAnimation("Opacity", animation)
舉起System.UnauthorizedAccessException的。我被告知「調用者不允許在這個對象上執行這個操作」。我究竟做錯了什麼?
@ user2950509嗨,這個話題的任何更新? –