Help with WPF

Willie Trombone

Honorary Master
Joined
Jul 18, 2008
Messages
60,038
Eish... I have to put together a Windows app so picked wpf instead of windows forms to learn something new.
I'm having a bit of hassle with something really simple. Well, kind of hassle. The code snippet below works, it's just not elegant - there must be a better way to implement a flashing text box:

Flash the background of a text box named 'Code' red and white twice each with 1/2 sec between changes. This works, but behold the worst snippet of code I've written in a while lol. Excuse the indenting, I'll try sort it out:
Code:
Task.Delay(500).ContinueWith(_ =>
   {
      this.Dispatcher.Invoke(() =>
      {
         Code.Background = Brushes.Red;
      });
   });
Task.Delay(1000).ContinueWith(_ =>
   {
      this.Dispatcher.Invoke(() =>
      {
         Code.Background = Brushes.White;
      });
   });
Task.Delay(1500).ContinueWith(_ =>
   {
      this.Dispatcher.Invoke(() =>
      {
         Code.Background = Brushes.Red;
      });
   });
Task.Delay(2000).ContinueWith(_ =>
   {
      this.Dispatcher.Invoke(() =>
      {
         Code.Background = Brushes.White;
      });
   });


My second problem is the text box is a masked textbox (Extended WPF Toolkit) with a mask of "000 000". After the above flashing routine, I want to reset the textbox to the default of no entered text except the mask and move the cursor to the beginning again as if nothing had been entered in it... any shortcuts to that?
I feel like a poep asking for help with a Windows app lol but I'm lost with WPF right now. I like short and sweet.
*EDIT* Second problem has been solved by setting the Code.Text property to "___ ___". What a daft solution, but there you have it - a masked textbox has a default text value that matches the mask format (???!) That even sends the caret to the beginning again.
 
Last edited:
Top