Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

XAML code snippets in Visual Basic 2008

As you probably know, Microsoft Visual Studio 2008 offers an important mechanism for reusable code snippets. This feature is not available for the XAML code editor in WPF applications. So if we need to use XAML code snippets, we can run external tools such as the Snippet Manager which allows draggin'n'dropping snippets versus the XAML editor. By the way, I personally like to have all that I need inside the IDE (if possible!).

We could consider to take the advantage of an internal IDE feature such as the drag'n'drop of text onto Visual Studio's toolbox that is good also for XAML code snippets. I'm going to describe what I mean with explanations.

Let's run Visual Studio 2008 (or Visual Basic 2008 Express Edition) and create a new WPF project. Then, we can write a XAML code snippet that we may think as reusable (in my small example I wrote a minimal style for Buttons).

Once we've done this, let's expand the Toolbox and create a new tab called "My XAML Code Snippets" (right click on the Toolbox -> Add Tab):

Let's select our code snippet from within the XAML editor and drag it onto the new tab:

When we'll drop the code snippet, we'll get the following result:

Now we have our XAML code snippets in the Toolbox. We'll be able to drag it onto the code editor every time we need it. The only issue with this technique is that the newly added "My XAML Code Snippets" tab will be shown in the toolbox also when writing Visual Basic code (this is because the Toolbox is acting as a text repository) but you won't probably worry about this situation.

Alessandro

Print | posted on domenica 19 aprile 2009 17:33 | Filed Under [ Visual Studio 2008 Visual Basic Windows Presentation Foundation ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET