Prev | Current Page 138 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

..
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3))
Dim generator As New AnswerGenerator()
txtAnswer.Text = generator.GetRandomAnswer(txtQuestion.Text)
Me.Cursor = Nothing
End Sub
As you may have noticed from the signature of this event handler, the event model inWPF
is different than in earlier versions of .NET. It supports a new model that relies on event routing.
You??™ll learn more in Chapter 6.
In many situations, you??™ll use attributes to set properties and attach event handlers on the
same element. WPF always follows the same sequence: first it sets the Name property (if set),
then it attaches any event handlers, and lastly it sets the properties. This means that any event
handlers that respond to property changes will fire when the property is set for the first time.
nNote It??™s possible to embed code (such as event handlers) directly in a XAML document using the Code
element. However, this technique is thoroughly discouraged and it doesn??™t have any practical application in
WPF. This approach isn??™t supported by Visual Studio and it isn??™t discussed in this book.
Visual Studio helps you out with IntelliSense when you add an event handler attribute.
Once you enter the equals sign (for example, after you??™ve typed Click= in the