Alessandro Del Sole's Blog

{ A programming space about Microsoft® .NET® }

  Home :: Contact :: Syndication  :: Login
  73 Posts :: 10 Stories :: 141 Comments :: 1729 Trackbacks

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 2010

Order my book about VB 2010 on Amazon My book "Visual Basic 2010 Unleashed" is available. Click the cover!

Your visits

Windows Live Alerts

Vsi Builder 2008

My tool for VS 2005/2008 Download Vsi Builder, my dev tool for Visual Studio 2005/2008!

Add me to MSDN Social!

Follow me on Twitter!

Messenger me!


Grab this badge here!

CyberInstaller Beta Tester

Download CIS 2008!!

CodePlex download Download my open-source projects from CodePlex!

Search the blog



Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

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

posted on Sunday, April 19, 2009 2:33 PM

Feedback

# re: XAML code snippets in Visual Basic 2008 11/23/2009 7:58 AM Annie
Is there any customised way to add code snippet to toolbox, like how different users are using custom control by making use of dll?



# re: XAML code snippets in Visual Basic 2008 2/27/2010 11:53 AM Francois
Nice tip.
Thank you for sharing

Post Feedback

Title:
Name:
Url:
Comments: 
Codice di sicurezza
Protected by FormShield