July 17, 2008 by daggmano
Check out win2008workstation.com - it gives full details on how to set up Windows 2008 Server as a workstation, including enabling Aero and other Vista nicetites. I’m tempted, if only to get rid of the HP-specific stuff on my laptop.
Posted in Miscellaneous | Tagged Windows 2008 | No Comments »
July 14, 2008 by daggmano
I needed a function that would return a boolean indicating if any of the values from one list appeared in another list. I love extension methods…
public static bool ContainsOneOf<T>(this IList<T> first, IList<T> second)
{
foreach (T item in first)
{
if (second.Contains(item))
return true;
}
return false;
}
Remember to place this method in a public static class.
Posted in Coding | Tagged C#, generics, extension methods | No Comments »
I’ve been utilising Kevin Moore’s Bag-o-Tricks for WPF recently, but when I load my solution up in Visual Studio, I get a “The project location is not trusted” dialog. Turns out it is because I didn’t unblock the zip file before I unzipped it. Turns out there is a solution: have a look at this for more info and the solution.
Posted in Coding | Tagged Visual Studio | No Comments »
I am writing a WPF application which runs as a tool-style dialog on the desktop, and needs to be able to be minimized but not maximised. It seems that this is somthing the WPF designers didn’t quite anticipate, despite it having been pretty easy to achieve under Windows Forms.
After searching around the ‘net, I finally found some code that disabled both the minimize & maximize buttons, but took a couple shortcuts that I didn’t like (and besides, it was in VB…).
A bit of searching and a quick cleanup left me with a working result. Catch the Loaded event of your window, and put the following code into the handler:
// Import some references
using System.Interop;
using System.Runtime.InteropServices;
// Place these inside the class definition...
[DllImport("user32.dll")]
private extern static Int32 SetWindowLong(IntPtr hWnd, Int32 nIndex, Int32 dwNewLong);
[DllImport("user32.dll")]
private extern static Int32 GetWindowLong(IntPtr hWnd, Int32 nIndex);
private const Int32 GWL_STYLE = -16;
private const Int32 WS_MAXIMIZEBOX = 0x10000;
private const Int32 WS_MINIMIZEBOX = 0x20000;
// And finally the event handler...
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IntPtr hWnd = new WindowInteropHelper(this).Handle;
Int32 windowLong = GetWindowLong(hWnd, GWL_STYLE);
windowLong = windowLong & ~WS_MAXIMIZEBOX;
SetWindowLong(hWnd, GWL_STYLE, windowLong);
}
I have included the value for WS_MINIMIZEBOX in case you need it.
Posted in Coding | Tagged C#, Interop, WPF | No Comments »
June 26, 2008 by daggmano
I don’t normally get inspired by videos on the Internet, but this one is an exception. Enjoy…
Posted in Miscellaneous | 2 Comments »
June 23, 2008 by daggmano
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…)
Posted in Education | Tagged MCTS, Microsoft, MCP, .NET | No Comments »
June 12, 2008 by daggmano
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.
Posted in Coding | Tagged Event Handling, WPF, XAML | No Comments »
June 12, 2008 by daggmano
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…
Posted in Education | Tagged MCTS, Microsoft | No Comments »