If you’re like me, dealing with giant XAML files is problematic. I don’t seem to possess the mental stack that some XAMLers have that allows them to deal with pages upon pages of disorganized XAML code. I frequently run into this dilemma when I deal with WPF themes. They’re usually colors, brushes, styles and templates for every single WPF control in existence all crammed into one file. I have to rely on text searches for terms like “Button” to find what I’m looking for. I found myself pleading to the markup language gods for the regioning system I had grown so accustomed to in C#. My prayers combined with my Internet searches lacked the fecundity to bare any useful results, so I was on my own. Luckily, Visual Studio 2010 has a pretty easy-to-use Extension Framework. As such, I whipped up a plugin that allows XAML regions. Like most things of this nature, I see no pressing reason to hoard it all to myself.

XAML Regions Extension For Visual Studio 2010

XAML Regions Extension For Visual Studio 2010

Using The Extension

There’s nothing particularly complex about using this extension. I wanted to make it so that people without this extension didn’t have trouble working with code from people who did have the extension. I chose to make it so that XAML regions were defined in XML comments. One would start a XAML region by having a few lines that consist of

1
2
3
<!-- Region (Any Text You Want) -->
Your Code
<!-- EndRegion -->

Spacing, prefix hash characters, and description text are all generally optional. All of the following uses are supported:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!-- Region Hello World -->
Your code
<!-- End Region -->
 
<!-- RegionHello World -->
Your code
<!-- EndRegion -->
 
<!-- #Region Hello World -->
Your code
<!-- #End Region -->
 
<!-- #Region Hello World -->
Your code
<!-- #EndRegion -->
 
<!-- Region Hello World -->
Your code
<!-- End Region Hello World -->

That’s really all there is to it!

Grab it at the Visual Studio Gallery

Updated in 0.4

  1. Added the ability to have hash character prefixes (e.g., <!– #Region –>)
  2. IAdded the ability to have description text in the EndRegion area (e.g., <!– End Region (Your Text) –>)

Enjoy!