Skip to content

Instantly share code, notes, and snippets.

@moraismateus
Forked from Juansero29/bprop.snippet
Last active May 13, 2022 16:43
Show Gist options
  • Save moraismateus/019694c3775bb1b23eb0f0b3c04caf47 to your computer and use it in GitHub Desktop.
Save moraismateus/019694c3775bb1b23eb0f0b3c04caf47 to your computer and use it in GitHub Desktop.
Modern Bindable Property Snippet for Xamarin Forms.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Bindable Property</Title>
<Description>Modern Xamarin Forms Bindable Property</Description>
<Author>Mateus Morais(moraismateus), Juan R. (Juansero29) and Parth Patel (parth7676)</Author>
<Shortcut>bprop</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>PropertyName</ToolTip>
<Default>PropertyName</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>ClassOwner</ID>
<ToolTip>ClassOwner</ToolTip>
<Default>ClassOwner</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyType</ID>
<ToolTip>PropertyType</ToolTip>
<Default>PropertyType</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
#region $PropertyName$
public static readonly BindableProperty $PropertyName$Property = BindableProperty.Create(
nameof($PropertyName$),
typeof($PropertyType$),
typeof($ClassOwner$),
propertyChanged: (obj, oldValue, newValue) =>
{
var me = obj as $ClassOwner$;
if (newValue != null && !(newValue is $PropertyType$)) return;
var old$PropertyName$ = ($PropertyType$)oldValue;
var new$PropertyName$ = ($PropertyType$)newValue;
me?.$PropertyName$Changed(old$PropertyName$, new$PropertyName$);
});
private void $PropertyName$Changed($PropertyType$ old$PropertyName$, $PropertyType$ new$PropertyName$)
{
}
public $PropertyType$ $PropertyName$
{
get => ($PropertyType$)GetValue($PropertyName$Property);
set => SetValue($PropertyName$Property, value);
}
#endregion $end$]]>
</Code>
<Imports>
<Import>
<Namespace>Xamarin.Forms</Namespace>
</Import>
<Import>
<Namespace>System.Collections.Generic</Namespace>
</Import>
</Imports>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>PropertyName</ToolTip>
<Default>PropertyName</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>ClassOwner</ID>
<ToolTip>ClassOwner</ToolTip>
<Default>ClassOwner</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyType</ID>
<ToolTip>PropertyType</ToolTip>
<Default>PropertyType</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
#region $PropertyName$
public static readonly BindableProperty $PropertyName$Property = BindableProperty.Create(
nameof($PropertyName$),
typeof($PropertyType$),
typeof($ClassOwner$),
propertyChanged: (obj, oldValue, newValue) =>
{
var me = obj as $ClassOwner$;
if (newValue != null && !(newValue is $PropertyType$)) return;
var old$PropertyName$ = ($PropertyType$)oldValue;
var new$PropertyName$ = ($PropertyType$)newValue;
me?.$PropertyName$Changed(old$PropertyName$, new$PropertyName$);
});
private void $PropertyName$Changed($PropertyType$ old$PropertyName$, $PropertyType$ new$PropertyName$)
{
}
public $PropertyType$ $PropertyName$
{
get => ($PropertyType$)GetValue($PropertyName$Property);
set => SetValue($PropertyName$Property, value);
}
#endregion $end$]]>
</Code>
<Imports>
<Import>
<Namespace>Xamarin.Forms</Namespace>
</Import>
<Import>
<Namespace>System.Collections.Generic</Namespace>
</Import>
</Imports>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment