Skip to content

Instantly share code, notes, and snippets.

@andreas-nesheim
Last active June 9, 2020 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreas-nesheim/00a1821f372dd43427b3cd2e93c1f6a2 to your computer and use it in GitHub Desktop.
Save andreas-nesheim/00a1821f372dd43427b3cd2e93c1f6a2 to your computer and use it in GitHub Desktop.
XAML code snippets
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>CollectionView Template</Title>
<Author>Andreas Nesheim</Author>
<Description>Snippet for creating a simple CollectionView with a bindable ItemsSource</Description>
<Shortcut>cv</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>ListName</ID>
<ToolTip>Name of the ItemsSource to bind to</ToolTip>
<Default>Items</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName1</ID>
<ToolTip>Image source in the ItemsSource to bind to</ToolTip>
<Default>ImageUrl</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName2</ID>
<ToolTip>Name of the property in the ItemsSource to bind to</ToolTip>
<Default>Name</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName3</ID>
<ToolTip>Name of the property in the ItemsSource to bind to</ToolTip>
<Default>Location</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="XAML">
<![CDATA[<CollectionView ItemsSource="{Binding $ListName$}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2"
Source="{Binding $PropertyName1$}"
Aspect="AspectFill"
HeightRequest="60"
WidthRequest="60" />
<Label Grid.Column="1"
Text="{Binding $PropertyName2$}"
FontAttributes="Bold" />
<Label Grid.Row="1"
Grid.Column="1"
Text="{Binding $PropertyName3$}"
FontAttributes="Italic"
VerticalOptions="End" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Formatted String</Title>
<Author>Andreas Nesheim</Author>
<Description>Snippet for a FormattedString Label</Description>
<Shortcut>stringf</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>String1</ID>
<ToolTip>Text for the first span</ToolTip>
<Default>Red bold, </Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>String2</ID>
<ToolTip>Text for the second span</ToolTip>
<Default>italic small.</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="XAML">
<![CDATA[<Label LineBreakMode="WordWrap">
<Label.FormattedText>
<FormattedString>
<Span Text="$String1$" TextColor="Red" FontAttributes="Bold" />
<Span Text="$String2$" FontAttributes="Italic" FontSize="Small" />
</FormattedString>
</Label.FormattedText>
</Label>]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>ListView Template</Title>
<Author>Andreas Nesheim</Author>
<Description>Snippet for creating a simple ListView with a bindable ItemsSource</Description>
<Shortcut>lv</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>ListName</ID>
<ToolTip>Name of the ItemsSource to bind to</ToolTip>
<Default>Items</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>Name of the property in the ItemsSource to bind to</ToolTip>
<Default>Name</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="XAML">
<![CDATA[<ListView ItemsSource="{Binding $ListName$}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding $PropertyName$}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment