Skip to content

Instantly share code, notes, and snippets.

@mzhukovs
Created July 9, 2018 04:33
Show Gist options
  • Save mzhukovs/96111290d0399659680cf57014de30f2 to your computer and use it in GitHub Desktop.
Save mzhukovs/96111290d0399659680cf57014de30f2 to your computer and use it in GitHub Desktop.
Xamarin Forms Bindable Property Code Snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>Xamarin Bindable Property</Title>
<Author>Mark Zhukovsky</Author>
<Description>Code snippet for an automatically implemented Xamarin Forms BindableProperty.</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>xambprop</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>name</ID>
<ToolTip>Enter the name of the Property</ToolTip>
<Default>name</Default>
<Function>
</Function>
</Literal>
<Literal default="true" Editable="false">
<ID>owner</ID>
<ToolTip>The class to which the Bindable Property belongs</ToolTip>
<Function>ClassName()</Function>
<Default>Owner</Default>
</Literal>
<Literal Editable="true">
<ID>type</ID>
<ToolTip>The type of the Property</ToolTip>
<Default>Type</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[public static readonly BindableProperty $name$Property =
BindableProperty.Create(nameof($name$), typeof($type$), typeof($owner$), default($type$),
BindingMode.TwoWay, propertyChanged: On$name$Changed);
public $type$ $name$
{
get => ($type$)GetValue($name$Property);
set => SetValue($name$Property, value);
}
private static void On$name$Changed(BindableObject bindable, object oldValue, object newValue)
{
var control = ($owner$)bindable;
var new$name$Value = ($type$)newValue;
}$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment