Thursday, December 9, 2010

Migrating TFS 2008->2010: Where are my links?!

I've recently been asked to write a simple tool that checks if all links between TFS WorkItems and ChangeSets have migrated successfully from TFS 2008 to TFS 2010, and migrates missing links if necessary.

The interesting thing was why did that task even arise. At that moment, it seemed that the tool that migrates projects from TFS 2008 to 2010 somehow looses all links. Yes, the tool said migration was completed, but there were no links. Later, by the time I completed the tool, the links had somehow got to the destination. Autopsy has shown that after the tool had completed, it started a Windows service, which apparently completed the migration in background.

Those guys in TFS team... are they mad?

Thursday, December 2, 2010

WPF: Color your items with data-binding

I've recently run into a tricky task while implementing a Windows Eplorer-like browser feature in the project I work at. I have a collection of data items (in my View Model) that have a 'Type' property of enumeration type, and I want to display them in a ListBox. The tough requirement is that items should be colored depending on their Type property value, including custom Foreground and Background of selected items (for various combinations of IsSelected, IsSelectionActive and IsEnabled properties).

Wednesday, December 1, 2010

WPF Hyperlink default style

Tried to find the default style of a Hyperlink and discovered that neither Google, nor Expression Blend or ShowMeTheTemplate have it. So I had to disassemble WPF assembly with .NET Reflector+BAML viewer. Here is the style for Aero NormalColor theme, just for reference purposes:
   <Style x:Key="{x:Type Hyperlink}" TargetType="{x:Type Hyperlink}">
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="Red" />
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground"
                       Value="{DynamicResource {x:Static GrayTextBrush}}" />
            <Trigger Property="IsEnabled" Value="true">
                <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="TextDecorations" Value="Underline" />
Oh, a slight surprise for me was that the hyperlink colors are not bound to any SystemColor members. No, they are just Red and Blue nailed in the style. Why?....

WPF ItemContainerStyleSelector unlimited: going data-bound

Use case
You have a View Model which contains a collection of items. In View, items are presented in an ItemsControl, say ListBox, and containers for each item should have different styles. Styles are selected depending on some property of view model items, e.g. Type property. An example of such situation is when each Type has its own combination of colors.
At this point, the task can be easily solved using a StyleSelector which encapsulates the selection logic. It's rather simple, so I won't discuss it.
To make task really interesting, let's require the selection logic to track changes in data items like Bindings do, i.e. if the value of the Type property changes, Style should be changed in the moment.