我在哪里可以下载Visual Studio的片段,比如pf pmvx,cmvx和其他? 我虽然可以在github项目中使用,但找不到它们......
答案 0 :(得分:18)
我已经创建了自己的。请记住,这些是ReSharper的模板。
#region $region$ command
private MvxCommand _$NAME$Command;
public ICommand $PNAME$Command
{
get
{
_$NAME$Command = _$NAME$Command ?? new MvxCommand(Do$PNAME$Command);
return _$NAME$Command;
}
}
private void Do$PNAME$Command()
{
$END$
}
#endregion
#region $region$
private $TYPE$ _$NAME$;
public $TYPE$ $PNAME$
{
get { return _$NAME$; }
set { _$NAME$ = value; RaisePropertyChanged(() => $PNAME$); }
}
#endregion
$END$
var set = this.CreateBindingSet<$VIEW$, $VIEW$Model>();
set.Bind($ELEMENT$).To(vm => vm$END$);
set.Apply();
您可以使用ReSharper&gt;模板浏览器&gt;动态模板&gt;新模板将它们添加到ReSharper。
请随意改变它们。
答案 1 :(得分:6)
这是基于Aboo上面答案的片段的原生VS版本。
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvxprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { if($backingfield$ == value) return; $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Command</Title>
<Description>Insert a Command declaration for an MvvMCross View Model</Description>
<Shortcut>mvxcom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$Command = $backingfield$Command ?? new MvxCommand(Do$Name$Command);
return $backingfield$Command;
}
}
private void Do$Name$Command()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvxset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
答案 2 :(得分:3)
如果我的推定是正确的,那么你指的是Stuart在他的MvvmCross演示中使用的捷径。这些是他使用ReSharper编写并分配给快捷方式的代码片段,并且不公开,但是如果你很好地问他们可以导出和共享它们。当然,您可以使用this tutorial
制作自己的“实时模板”答案 3 :(得分:1)
我修改了@ Coasty的答案,包括一个改编自https://stackoverflow.com/questions/17187113/how-can-i-use-async-in-an-mvvmcross-view-model的异步命令,并更改了快捷方式,使它们不再与mvx名称空间冲突。
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvvmcrossprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Command</Title>
<Description>Insert a Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrosscom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(Do$Name$);
return $backingfield$;
}
}
private void Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Async Command</Title>
<Description>Insert an Async Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrossacom</Shortcut>
<Author>Benjamin Hysell (based on Andrew Coates Command Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(async () => await Do$Name$());
return $backingfield$;
}
}
private async Task Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvvmcrossset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>