Sometimes it’s fun to do something that any self-respecting developer would cringe if they saw someone else do it. That’s kind of how I feel about abusing the capabilities of C# 4′s dynamic binding capabilities. Even though I stubbornly resisted the idea of adding dynamic binding to C#, I find myself playing around with it every now and then to make really ugly code look nicer. For example, let’s consider the case where you’re matching a US telephone number (with optional extension) against a regular expression and separating the individual components into separate variables. In the US telecom industry it’s [...]

Windows tablets with external monitors

It’s been a while since I used a Windows Tablet PC with an external monitor. One thing that used to drive me nuts (I think as recently as Vista) was the fact that if you set the external monitor as your “main” display, the pen would all of a sudden control the cursor on the external monitor, not the tablet display. No longer! I just plugged in an external monitor and the pen still controls the tablet display. But it gets better. My HP 2710P tablet has a very odd shaped hinge. So it doesn’t fit very well into the [...]

Here’s a quickie. I had an issue where I have a ListBox that will (should) never scroll but I need its item selection capability. It is inside of another ScrollViewer (along with some other controls) and that outer ScrollViewer should be what scrolls. Unfortunately ListBox was eating the MouseWheel events, preventing the outer ScrollViewer from scrolling. A quick Google search didn’t turn up much. I didn’t want to set IsHitTestVisible=False because like I said, I need the selection ability. I also thought changing the template or subclassing ScrollViewer was a bit drastic. So instead I came up with the following [...]

Quick Tip - Troubleshoot broken OData response using Notepad

Ran into a bit of an issue today when an application I developed stopped working. Fortunately I built a pretty awesome tracing framework that I often drop into all my applications that lets me get at important runtime information from within the application. In this case I was able to see the WCF Data Services query that was being sent. It looked fine. The problem was that the response couldn’t be deserialized.

Colin Eberhardt has posted a neat multi-purpose value converter that tries various conventional conversion methods to convert from one type to another. This overcomes a frustrating limitation in WPF/Silverlight data binding where the XAML parser is seemingly more intelligent at converting literal values to target types than values sourced from binding expressions. Unfortunately, the TypeConverter usage will not work in Silverlight but perhaps using the XamlReader technique there’s something that could be done? Also, a couple of the readers in the comments had a great suggestion to derive the converter from MarkupExtension to simplify the XAML. I think I’m going [...]

Very cool Visual Studio extension - VS10x Code Map

I have been using this Visual Studio extension called VS10x Code Map by Michael Kiss and I love it. It sits on the left or right of the Visual Studio text editor and provides an attractive outline view of the properties, methods, regions, etc in the current code file and lets you quickly navigate to a particular member. I have tried other add-ins in the past that provided a code outline but they were usually slow, unattractive, or used a tree view style interface that I found to be more cumbersome than scrolling. The other nice thing about this one [...]

Windows 7 Style "Aero" ChildWindow Template

Silverlight 3 introduced a very useful control called a ChildWindow. This is a “modal” dialog box that can contain whatever content you give it and it floats above the rest of the application inside a Popup control. I say “modal” because unlike ShowDialog in WPF or Windows Forms, showing a ChildWindow via the Show method returns immediately, but it does disable the application’s RootVisual which prevents the user from interacting with the rest of the application while the window is showing.

As cool as this control is, I have always been pretty disappointed in the default behavior and look and feel of the ChildWindow class. For example, the animation as it opens and closes is very unnatural and distracting. The overlay that “dims” the rest of the application successfully indicates the modal nature of the control, but it’s too strong I think. In fact I’m fine with just the normal “grey out” that happens when the RootVisual is disabled.

A while back I had created a pretty lame ChildWindow template that kinda sorta looked like a Windows 7 Aero window. It was a half-hearted attempt but it looked a lot better than the above. But then I saw a question on StackOverflow asking about creating an Aero glass style window and I decided to revisit the problem and try to come up with something decent.

SwitchConverter - A "switch statement" for XAML

Download the example project which includes the source for SwitchConverter and SwitchedContent. I figured I would write some more about value converters since I think there’s a lot of cool things you can do with them, especially when you put a little extra effort into generalizing them. One thing I find I need to do often is to show content conditionally depending on a certain data binding condition. For example, let’s say we had a WeatherReport object that had a Condition property that had the following enumeration values: Sunny, Cloudy, Rain, Snow. We want to have a different image for [...]

I came across a question on StackOverflow that is a very frequently asked question regarding data binding in XAML. Given a boolean, how do you bind the opposite value to the target? The answer of course is to use a value converter (a class implementing IValueConverter) and invert the boolean in code. I do this a lot though so I have a NegateConverter in "Josh’s Toolbox". My NegateConverter can negate a lot of things, not just booleans. For example, numeric values, Visibility, Thickness, Point, etc. Now I’ll probably never need to negate a Point but I figured what the hell. [...]

I saw in my feed reader a posting that announced the release of the Visual Studio 2010 Pro Power Tools extension that was available in the Visual Studio 2010 Extension Manager. At first glance I thought it was the Power Tools extension that I’ve been using for a while. However, this is a totally separate extension that adds some very awesome features. Note that they go into a lot of detail on the enhanced document tab feature but although this is neat and useful, it’s not really in my top 3 features. I’ve emphasized my 3 favorite features. Document Well [...]