Xamarin.Forms: Lazy loaded Command snippet for Visual Studio
by
banditoth
February 24, 2021
.NET, Xamarin
0
This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.
Use xamcomm tab tab to generate commands in ViewModels with this snippet
Save the snippet file as {name}.snippet in Visual Studio’s folder: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC#\Snippets\1033\Visual C#
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Xamarin Lazy Command</Title>
<Shortcut>xamcomm</Shortcut>
<Description>Xamarin Command declaration code snippet for MVVM design pattern</Description>
<Author>banditoth.hu</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>BackFieldName</ID>
<ToolTip>Backfield Name</ToolTip>
<Default>_backfieldname</Default>
</Literal>
<Literal>
<ID>CommandName</ID>
<ToolTip>Command name</ToolTip>
<Default>CommandName</Default>
</Literal>
<Literal>
<ID>ActionToExecute</ID>
<ToolTip>Action to execute</ToolTip>
<Default>() => { return; /*TODO: Implement logic for this Command*/ }</Default>
</Literal>
<Literal>
<ID>ActionCanExecute</ID>
<ToolTip>Action to determine can execute</ToolTip>
<Default>() => true</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
private Command $BackFieldName$Command;
public Command $CommandName$Command
{
get { return $BackFieldName$Command ?? ($BackFieldName$Command = new Command($ActionToExecute$,$ActionCanExecute$)); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Tags In
Share
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Hi, I am András,
I am a seasoned software engineer from Budapest, Hungary with a strong focus on mobile app development using .NET MAUI and Xamarin.Forms. My expertise also extends to website building for my happy customers and other complex system designing. I am passionate about developing well-organized, maintainable software solutions.
#tagged
.net core (8)
.NET MAUI (27)
android (21)
Appstore (3)
azure (4)
azure devops (6)
bug (3)
ci (3)
dark mode (3)
devops (5)
docker (2)
entry (6)
error (13)
forms (4)
ios (15)
json (3)
listview (3)
macos (8)
maui (32)
maui error (4)
maui ios (4)
maui packages (4)
mvvm (3)
nuget (4)
osx (3)
osx visual studio (3)
pipelines (4)
Publish (4)
publish error (3)
recurrencetoolkit (4)
snippet (2)
sourcetree (3)
uwp (5)
versioning (2)
visual studio (10)
visual studio mac (3)
vscode (3)
vs mac (4)
windows (4)
xamarin (50)
xamarin android (17)
xamarin error (11)
xamarin forms (34)
xamarin ios (6)
xaml (3)