Visual Studio: Are XAML fragments supported?

Can I add XAML fragments for the XAML editor in Visual Studio 2010? For example, I would like to save myself from entering text and do something like this:

snippet: gr<TAB>

generates code:

<Grid>
    <Grid.RowDefinitions>

    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>

    </Grid.ColumnDefinitions>
</Grid>

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

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

and similarly for other XAML elements.

I think you understand ... The goal is to make these fragments available only in the XAML Visual Studio editor. Their presence in other code editors inside Visual Studio (for example, when editing .cs files) does not have a point.

+7
source share
3 answers

, - .

+2

VS 2019. :

, :

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <Tag Grid.Row="0" Grid.Column="0" />
</Grid>

Tag , , :

<?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>

.snippet, (Tools | Code Snippets Manager..., , IntelliSense ( XAML). ( ), .

enter image description here

IntelliSense ( , ), griddef Tab Tab .

CDATA Shortcut. :

<Declarations>
  <Literal Editable="true">
    <ID>TagName</ID>
    <ToolTip>Tag Name</ToolTip>
    <Default>TextBlock</Default>
  </Literal>
</Declarations>

, .

0
source

All Articles