how could I change my Label content to random letter by using DispatcherTimer C#? My DispatcherTimer doesn't execute Letter_Tick() function :|
My MainWindow.xaml
<Label x:Name="myLbl" Content="" FontSize="108" HorizontalContentAlignment="Center"/>
My main class (MainWindow.xaml.cs)
public MainWindow()
{
InitializeComponent();
letterRandomizer ob = new letterRandomizer(myLbl);
}
And my letterRandomizer class
class letterRandomizer
{
Random rand = new Random();
string newLetter = "";
Label MyLbl;
DispatcherTimer letter = new DispatcherTimer();
public letterRandomizer(Label myLbl)
{
this.MyLbl = myLbl;
letter.Tick += Letter_Tick;
letter.Interval = TimeSpan.FromSeconds(2);
}
private void Letter_Tick(object sender, EventArgs e)
{
MyLbl.Content = "";
newLetter = Convert.ToChar(rand.Next(65, 90)).ToString();
MyLbl.Content = newLetter;
}
}