I don’t normally get inspired by videos on the Internet, but this one is an exception. Enjoy…
I don’t normally get inspired by videos on the Internet, but this one is an exception. Enjoy…
Categories: Miscellaneous
I’ve just completed the Microsoft 70-536 exam, and… I passed!! Passing score was 700, I was able to answer and guess my way to 858!! (I think they’re out of approx. 1000).
I must say that I was dissappointed with the quality of the MS Press Self-Training book – there were many errors in the text and on the CD-ROM (including within the practice exams) that were not covered by the 50 or so pages of errata on the MS website, and the book did not cover all areas (in sufficient detail) to enable a passing mark.
That being said, it was enough to put me on the right track. A few years of experience with .NET 2.0 didn’t hurt, and the rest is just down to studying the MSDN site and doing as many practice exams from as many sources as possible (they all focus on different areas).
For me, I’m taking a few weeks off from study to finish a few odd jobs around the house, then I’ll probably be on to the .NET 3.5 WPF exam (whatever number that is…)
I just posted this up on the MSDN forums, and then worked out the answer myself (so posted my own answer – is that allowed?). Thought it would be good to keep track of for future reference, so here goes…
I’ve got an application where I need to validate a text field as the control loses focus (i.e. as the user thinks (s)he is finished with it), pop up a Message Box informing the user of their error, and then re-focus the TextBox.
My WPF includes (simplified)
<TextBox x:Name=“txText” LostFocus=“txText_LostFocus” /> which calls the following
private void txText_LostFocus(object sender, EventArgs e) { /* Check for valid input */ if (/* not valid */) { MessageBox.Show(“You have entered an incorrect value”); txText.Focus(); } } Problem is, the txText.Focus() line triggers the LostFocus event again, so I end up with a never-ending Message Box loop!
I am aware that I could get around this by using validators and adorners on the TextBox, but I would like the Message Box, and for the TextBox to keep focus if bad data is entered.
There doesn’t seem to be a PreviewLostFocus event – is this correct?
The light came on soon after…
And the answer is… I’m a dope.
Just minutes after posting this question I noticed that there is in fact a PreviewLostKeyboardFocus event. Capturing this event and setting e.Handled = true on an invalid input condition does exactly what I was after. Further, using a KeyboardFocusChangedEventArgs argument in the event handler allows me to check the NewFocus control, and if is equal to (eg) the Cancel button on my dialog, validation can be bypassed.
Categories: Coding
Tagged: Event Handling, WPF, XAML
I got about 4 hours sleep last night. Thanks, Round Earth Society! Some days I yearn for a flat earth, where we can all exist in the same time zone. For one, it would save on jetlag – not that I’ve ever suffered from that (or flown over more than 4 timezones, but that’s a story for another day).
Microsoft hosted a LiveMeeting Cram 4 Exams session last night dealing with my flavour of the month, 70-536. At least, it was last night here (12:30am – 1:30am), while Trika and the mob enjoyed a wonderful morning (7:30am – 8:30am the day before) at TechEd.
Of course, I could have just waited for the recording of the session to be released tomorrow, but there’s nothing quite like being there… virtually, at least…