C#:
public partial class MainWindow : Window
{
Storyboard a = new Storyboard();
int i;
public MainWindow()
{
InitializeComponent();
a.Completed += new EventHandler(a_Completed);
a.Duration = TimeSpan.FromMilliseconds(10);
a.Begin();
}
void a_Completed(object sender, EventArgs e)
{
textblock.Text = (++i).ToString();
a.Begin();
}
}
XAML:
<Window x:Class="Gui.MainWindow" x:Name="control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<Canvas>
<TextBlock Name="textblock"></TextBlock>
</Canvas>
What is wrong with this code? the storyboard stops after 20-50 rounds. Every time a different number
I believe it's because with your code there is no relation created between the Storyboard's animation clock and the TextBlock's Text DependencyProperty. if I had to guess I would say when the Storyboard was conking out, it was at a somewhat random time due to fouling the DependencyProperty (TextBlock.Text is a DependencyProperty) update pipeline. Creating such an association as below (either RunTimeline or RunStoryboard will work, but show alternate methods of looking at this):
This works for me for as long as I would let it run (~10 times longer than it ever took to conk out otherwise).
Tim