1
我有一個簡單的Storyboard
旋轉網格60度,然後回到0,但動畫沒有運行,我不知道爲什麼。我正在使用DispatcherTimer
來確保它按設定的時間間隔運行。我也嘗試在xaml中創建Storyboard
,並從Ticker事件中調用Storyboard.Begin()
,但沒有運氣。提前致謝。 調試時,我添加一個斷點北京時間事件動畫運行動畫沒有運行在Windows 8.1應用程序使用DispatcherTimer
MainPage.cs
public sealed partial class MainPage : Page
{
private DispatcherTimer timer;
public MainPage()
{
this.InitializeComponent();
Loaded += (s, args) =>
{
timer = new DispatcherTimer();
timer.Tick += Ticker;
timer.Interval = new TimeSpan(0, 0, 6);
timer.Start();
};
}
public void Ticker(object sender, object e)
{
var sb = new Storyboard();
var animation2 = new DoubleAnimationUsingKeyFrames();
var ease0 = new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 0 };
var ease1 = new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2500)), Value = 40 };
var ease2 = new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(4000)), Value = 60 };
var ease3 = new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(4100)), Value = 0 };
animation2.KeyFrames.Add(ease0);
animation2.KeyFrames.Add(ease1);
animation2.KeyFrames.Add(ease2);
animation2.KeyFrames.Add(ease3);
Storyboard.SetTargetProperty(animation2, "(UIElement.Projection).(PlaneProjection.RotationY)");
Storyboard.SetTarget(animation2, grid2);
sb.Children.Add(animation2);
sb.Completed += (se, argss) =>
{
};
sb.Begin();
}
MainPage.xaml中
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="grid2" Width="250" Height="250" Background="Blue" Grid.Column="1">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
</Grid>
</Grid>
感謝您的回答。這並不能解決使用DispatcherTimer以設定間隔運行故事板的問題,儘管它只運行一次。 – SWilko