Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: Is there XAML snippets support?

Is there any way to add XAML snippets for XAML editor in Visual Studio 2010? For example I'd like to save my self from some typing and have something like this:

snippet: gr<TAB>

generates code:

<Grid>
    <Grid.RowDefinitions>

    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>

    </Grid.ColumnDefinitions>
</Grid>

Then if I type for example: rd<TAB> it should generate <RowDefinition />

Similarly, cd<TAB> should generate <ColumnDefinition />

and similarly for other XAML elements.

I think you get the idea... The point is to make these snippets available only in XAML editor of the Visual Studio. Having them in other code editors inside Visual Studio (eg. when editing .cs files) doesn't have point.

like image 508
matori82 Avatar asked Apr 26 '12 20:04

matori82


People also ask

Does Visual Studio have snippets?

In Visual Studio there are two kinds of code snippet: expansion snippets, which are added at a specified insertion point and may replace a snippet shortcut, and surround-with snippets (C# and C++ only), which are added around a selected block of code.

How do I add a snippet in Visual Studio?

With a code file open in the editor, choose Snippets > Insert Snippet from the right-click menu, then My Code Snippets. You should see a snippet named Square Root. Double-click it. The snippet code is inserted in the code file.

How do I enable snippet code in Visual Studio?

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

How do I view XAML design in Visual Studio?

To open the XAML Designer, right-click a XAML file in Solution Explorer and choose View Designer. to switch which window appears on top: either the artboard or the XAML editor.


1 Answers

If you don't need parameters, then you can use the Toolbox!

Simply drag the code into the Toolbox and insert it wherever you want. This works for C# as well as for XAML.

From: http://blog.wpfwonderland.com/2012/04/16/xaml-snippets-and-visual-studio/

like image 199
Heiner Avatar answered Oct 08 '22 20:10

Heiner