It works in VS 2019.
The guide to use: Creating Code Snippets
Example, to insert:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Tag Grid.Row="0" Grid.Column="0" />
</Grid>
Tag
being an editable value to be set each time you insert the snippet, use this code:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Grid Default</Title>
<Description>Grid With Default Rows and Columns</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>griddef</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>TagName</ID>
<ToolTip>Tag Name</ToolTip>
<Default>TextBlock</Default>
</Literal>
</Declarations>
<Code Language="xaml">
<![CDATA[
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<$TagName$ Grid.Row="0" Grid.Column="0" />
</Grid>
$selected$$end$]]>
</Code>
</Snippet>
</CodeSnippet>
This file can be saved anywhere with the extension .snippet
, then use the snippets manager (Tools | Code Snippets Manager...
to import the file to the standard place used by IntelliSense (don't forget to select type XAML). You may also create the file directly at the final place (visible in the snippet manager dialog below) to save the import step.
The shorcut may not appear in IntelliSense (this was my case, the reason is still unknown to me), but typing griddef
TabTab will insert the template.
For your specific needs, replace the code in CDATA
element, and change the value in Shortcut
element. You may also remove this section:
<Declarations>
<Literal Editable="true">
<ID>TagName</ID>
<ToolTip>Tag Name</ToolTip>
<Default>TextBlock</Default>
</Literal>
</Declarations>
if you don't need any editable value, or adapt it according to the guide mentioned at the beginning.
Grid.ColumnDefinitions
) using JetBrains Resharper. Obviously this is not an answer to your question as I don't know if you have a Resharper license. – Hyperventilation