The following code is counting up starting from 1 to forever by using Timer.
XAML codes:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Label x:Name="myLabel"/>
</Grid>
</Window>
vb.net codes:
Class MainWindow
Dim myDispatcherTimer As New Windows.Threading.DispatcherTimer With {.Interval = TimeSpan.FromSeconds(1)}
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
AddHandler myDispatcherTimer.Tick, AddressOf Me.Hello
myDispatcherTimer.Start()
End Sub
Public Sub Hello()
Static myStatic As Integer = 0
myStatic = myStatic + 1
myLabel.Content = myStatic
End Sub
End Class
I want to count up by using Double Animation instead of by using Timer.
Is it possible?
Thanks in advance.
You may create an attached property of type
doublethat sets theContentproperty of any ContentControl (e.g. a Label) to which it is applied.Then animate that property by an appropriate DoubleAnimation.
Since you apparently only want to show integer values, you may as well use an
Int32Animationwith an attached property of typeint.with