I am developing a windows phone game in expression blend that generate random numbers. The problem is that i want to start my storyboard after certain seconds the page loaded. I have tried implementing Timespan.FromSeconds(5) but it didn't work. I want the storyboard to be played when my timer stops. Also i have tried to start storyboard in "if" condition of dispathertimer_Tick method but it too didn't work. Please suggest me alternative for that.
DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public MainPage()
{
InitializeComponent();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
this.Loaded += LayoutRoot_Loaded;
}
int count = 5;
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
count--;
if (count < 0)
{
dispatcherTimer.Stop();
timer.Text = "Time Over";
count = 5;
}
else
{
timer.Text = count.ToString();
}
}
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
expr.Text = num.Next(100).ToString();
rectangle.BeginTime = TimeSpan.FromSeconds(5);
}
Storyboardhas a propertyBeginTime. Just set it to 5 seconds.In XAML:
or C#: