I have trying a simple repeat animation on xaml page as below:
<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>
Then after that, I plan to get control on idle page with the code below (Find from another site):
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);
}
}
}
The problem that I can summarize is:
- Because of that animation running on forever, the idle control is not firing. How to make it work?