Last active
July 11, 2018 14:20
-
-
Save mniak/d27eeceec091368c194b to your computer and use it in GitHub Desktop.
Collection of MVVM #snippet #wpf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>ViewModel Property</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a property that gets and sets the ViewModel (DataContext) of the object.</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vm</Shortcut> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>VmType</ID> | |
<ToolTip>ViewModel type</ToolTip> | |
<Default>MainViewModel</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>CommandName</ID> | |
<ToolTip>CommandName</ToolTip> | |
<Default>CommandName</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>CmdName</ID> | |
<ToolTip>CmdName</ToolTip> | |
<Default>CmdName</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[public $VmType$ ViewModel | |
{ | |
get | |
{ | |
return ($VmType$)DataContext; | |
} | |
set | |
{ | |
DataContext = value; | |
} | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>ViewModel Property - Get Only</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a property that gets the ViewModel (DataContext) of the object.</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vmg</Shortcut> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>VmType</ID> | |
<ToolTip>ViewModel type</ToolTip> | |
<Default>MainViewModel</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[public $VmType$ ViewModel | |
{ | |
get | |
{ | |
return ($VmType$)DataContext; | |
} | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>Bindable Property</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a bindable property in the ViewModel.</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vmprop</Shortcut> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>Type</ID> | |
<ToolTip>Type</ToolTip> | |
<Default>string</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>AttributeName</ID> | |
<ToolTip>Attribute Name</ToolTip> | |
<Default>_myProperty</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>InitialValue</ID> | |
<ToolTip>Initial Value</ToolTip> | |
<Default>string.Empty</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>PropertyName</ID> | |
<ToolTip>Property Name</ToolTip> | |
<Default>MyProperty</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[private $Type$ $AttributeName$ = $InitialValue$; | |
public $Type$ $PropertyName$ | |
{ | |
get | |
{ | |
return $AttributeName$; | |
} | |
set | |
{ | |
Set(() => this.$PropertyName$, ref this.$AttributeName$, value); | |
} | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>Bindable RelayCommand with Parameter</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a RelayCommand with parameter</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vmcmdp</Shortcut> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>CmdName</ID> | |
<ToolTip>The command name</ToolTip> | |
<Default>MyCommand</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>ParameterType</ID> | |
<ToolTip>The parameter type</ToolTip> | |
<Default>string</Default> | |
<Function> | |
</Function> | |
</Literal> | |
<Literal Editable="true"> | |
<ID>ParameterName</ID> | |
<ToolTip>The parameter name to the method</ToolTip> | |
<Default>param</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[private RelayCommand<$ParameterType$> cmd$CmdName$; | |
public RelayCommand<$ParameterType$> $CmdName$ | |
{ | |
get | |
{ | |
if (cmd$CmdName$ == null) | |
cmd$CmdName$ = new RelayCommand<$ParameterType$>($CmdName$Execute); | |
return cmd$CmdName$; | |
} | |
} | |
public void $CmdName$Execute($ParameterType$ $ParameterName$) { }]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>Bindable RelayCommand</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a RelayCommand</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vmcmd</Shortcut> | |
</Header> | |
<Snippet> | |
<Imports> | |
<Import> | |
<Namespace>using GalaSoft.MvvmLight.Command</Namespace> | |
</Import> | |
</Imports> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>CmdName</ID> | |
<ToolTip>The command name</ToolTip> | |
<Default>CommandName</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[private RelayCommand cmd$CmdName$; | |
public RelayCommand $CmdName$ | |
{ | |
get | |
{ | |
if (cmd$CmdName$ == null) | |
cmd$CmdName$ = new RelayCommand($CmdName$Execute); | |
return cmd$CmdName$; | |
} | |
} | |
public void $CmdName$Execute() { }]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>ViewModel Class</Title> | |
<Author>Andre Guilherme</Author> | |
<Description>Creates a ViewModel class</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>newvm</Shortcut> | |
</Header> | |
<Snippet> | |
<References> | |
<Reference> | |
<Assembly>GalaSoft.MvvmLight</Assembly> | |
</Reference> | |
</References> | |
<Imports> | |
<Import> | |
<Namespace>GalaSoft.MvvmLight</Namespace> | |
</Import> | |
</Imports> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>ViewModelName</ID> | |
<ToolTip>The ViewModel name</ToolTip> | |
<Default>NewVm</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$" Kind="type decl"><![CDATA[public class $ViewModelName$ViewModel : ViewModelBase | |
{ | |
public $ViewModelName$ViewModel() | |
{ | |
if (IsInDesignMode) | |
{ | |
PrepareDesignData(); | |
} | |
else { } | |
} | |
private void PrepareDesignData() | |
{ | |
$end$ | |
} | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
<Title>ViewModel Action</Title> | |
<Author>admin</Author> | |
<Description> | |
</Description> | |
<HelpUrl> | |
</HelpUrl> | |
<Shortcut>vmaction</Shortcut> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="true"> | |
<ID>ActionName</ID> | |
<ToolTip>Action Name</ToolTip> | |
<Default>Close</Default> | |
<Function> | |
</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp" Delimiter="$"><![CDATA[public Action $ActionName$Action { get; set; } | |
private void Raise$ActionName$Action() | |
{ | |
if ($ActionName$Action != null) | |
$ActionName$Action(); | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment