Skip to content

Instantly share code, notes, and snippets.

@JamestsaiTW
Last active August 24, 2022 04:36
Show Gist options
  • Save JamestsaiTW/3b400c7f680f1379c13233af9ceb20d6 to your computer and use it in GitHub Desktop.
Save JamestsaiTW/3b400c7f680f1379c13233af9ceb20d6 to your computer and use it in GitHub Desktop.
The code snippet of MVVM & Binding for .NET MAUI / Xamarin.Forms
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>nprop</Title>
<Shortcut>nprop</Shortcut>
<Description>使用泛型 Notify 的屬性和支援欄位程式碼片段</Description>
<Author>James Tsai</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>field</ID>
<ToolTip>欄位名稱</ToolTip>
<Default>myField</Default>
</Literal>
<Literal>
<ID>type</ID>
<ToolTip>屬性類型</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>屬性名稱</ToolTip>
<Default>MyProperty</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[private $type$ _$field$;
public $type$ $property$
{
get { return _$field$;}
set { OnPropertyChanged<$type$>(ref _$field$, value );}
}
$end$]]>
</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>Xamarin.Forms Command</Title>
<Shortcut>xfcmd</Shortcut>
<Description>使用 Xamarin.Forms 的繫結命令程式碼片段</Description>
<Author>James Tsai</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Command 命名名稱</ToolTip>
<Default>MyNew</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
public ICommand $name$Command
{
get
{
return new Command(() =>
{
$end$
});
}
}
]]>
</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>Xamarin.Forms Command</Title>
<Shortcut>xftcmd</Shortcut>
<Description>使用 Xamarin.Forms 的繫結命令程式碼片段</Description>
<Author>James Tsai</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>參數型別</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>name</ID>
<ToolTip>Command 命名名稱</ToolTip>
<Default>MyNew</Default>
</Literal>
<Literal>
<ID>arg</ID>
<ToolTip>參數名稱</ToolTip>
<Default>arg</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
public ICommand $name$Command
{
get
{
return new Command<$type$>(($arg$) =>
{
$end$
});
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment