我在 xaml 页面上尝试了一个简单的重复动画,如下所示:
<StackPanel Canvas.Left="1" Canvas.Top="1">
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard x:Name="sb_PathGeometry" RepeatBehavior="Forever">
<PointAnimationUsingPath Storyboard.TargetName="PathGeometry"
Storyboard.TargetProperty="Center"
Duration="0:0:1">
<PointAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M 10,0 L 10,-182 L -199,-182" />
</PointAnimationUsingPath.PathGeometry>
</PointAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
然后,我计划使用下面的代码控制空闲页面(从另一个站点查找):
using System.Windows.Threading;
using System.Windows.Interop;
namespace DS
{
public partial class MontagePage : Page
{
private EventHandler handler;
public MontagePage()
{
InitializeComponent();
handler = delegate
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(4);
timer.Tick += delegate
{
if (timer != null)
{
timer.Stop();
timer = null;
System.Windows.Interop.ComponentDispatcher.ThreadIdle -= handler;
ComponentDispatcher_ThreadIdle();
System.Windows.Interop.ComponentDispatcher.ThreadIdle += handler;
}
};
timer.Start();
//System.Windows.Interop.ComponentDispatcher.ThreadIdle -= handler;
Dispatcher.CurrentDispatcher.Hooks.OperationPosted += delegate
{
if (timer != null)
{
timer.Stop();
timer = null;
}
};
};
ComponentDispatcher.ThreadIdle += handler;
}
void ComponentDispatcher_ThreadIdle()
{
//Go to IdlePage.xaml
IdlePage idlepage = new IdlePage();
this.NavigationService.Navigate(idlepage);
}
}
}
我可以总结的问题是:
- 由于该动画一直在运行,因此空闲控件不会触发。如何让它发挥作用?