Yesterday, I posted a question on the Microsoft Blend Forums:
I received a couple of emails from folks requesting the utility, so I thought I'd post it here. You can download the utility itself and/or the source code:
The source code is a Visual Studio 2008 project; Microsoft .NET Framework 2.0, VB.
The reason we want to sort the resources alphabetically is that we are creating a naming standard for the resources. Once we name them properly, we'll automatically get them sorted by type as well.
Below I have more details on the utility and screenshots.
Screenshots and details
In Microsoft Blend, a graphics designer can create a resource dictionary and create resources such as DrawingBrush, LinearGradientBrush, SolidColorBrush, Color, Geometry, Style, etc...
My co-worker has created 192 such resources and at this point, they are not well organized. Here's a screenshot of the resources in Blend:
Notice that he can't see the type of resource from the "Resources" tab. In addition the only way to sort the resources is by moving them around (drag and drop).
If we look at the XAML, it's the same issue, we can copy and paste the resources, but it would be a pain to sort them all.
Here's another view of the same XAML, using XMLSPY. Notice the resource names (x:Key) and how they are not sorted at all (userIcon, folder_cover, etc...):
One problem that I didn't solve is that the namespaces attributes were added to the different resource nodes. Notice every resource has additional attributes such as:
Therefore, after running the Resource Dictionary Sorter, you must manually remove this namespace from every resource. You can use any text editor to do this, I use "UltraStudio":
Replace it with nothing (blank) and click "Replace All":
Our team will now start naming our resources, appending them with 2 or 3 letters that describe the type of resource, for example:
- lgbBackgroundBodyBlue for a <LinearGradientBrush>
- scbActiveWindow for a <SolidColorBrush>
- dbInvalidDocument for a <DrawingBrush>
We'll then automatically have all resources sorted by type as well - this will makes it much easier to find the resource that needs to be applied to a specific control: