Copying XAML code with CopySourceAsHtml

The CopySourceAsHtml plugin for Visual Studio is good for copying a block of sourcecode where you want to keep the syntax highlighting. Without highlighting the code looks like this.

string message = “Hello World”;

Kind of boring, uninspiring and…just blah. But when you use CopySourceAsHtml you get like this instead.

string message = "Hello World";

Which is a lot easier to read. Now, the last couple of days I’ve been reading up on WPF (Windows Presentation Foundation), and it uses a new syntax called XAML. When I tried to rightclick on the selected text in a .xaml file in VS2008 I didn’t have the CopyAsHtml option in the context menu. Bummer!

Fortunately there is an easy workaround. Just use the Edit menu, and you’ll find “Copy As HTML…” there.

Copy as Html in Edit menu

Copy as Html in Edit menu

And then you get pretty XAML code, like this.

        <Button Content="Click me!">
            <Button.Background>
                <LinearGradientBrush>
                    <GradientStop Color="WhiteSmoke" Offset="0.2" />
                    <GradientStop Color="Gray" Offset="0.8" />
                </LinearGradientBrush>
            </Button.Background>
        </Button>

Leave a Reply