Uso este un montón y tiene definidos lugares para el valor por defecto, el método call-back e incluso asigna la instancia de la clase que llama al call-back a una variable automaticamente.
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Dependency Property With CallBack</Title>
<Shortcut>propdpCallBack</Shortcut>
<Description>Creates a dependency property with it's callback method</Description>
<Author>Jose Sanchez</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>PublicName</ID>
<Default>PropertyName</Default>
<ToolTip>Public name of the depencency property</ToolTip>
</Literal>
<Literal>
<ID>type</ID>
<Default>string</Default>
<ToolTip>Type of the property</ToolTip>
</Literal>
<Literal>
<ID>ParentClassType</ID>
<Default>UserControl</Default>
<ToolTip>Type of the parent class of the dependency property</ToolTip>
</Literal>
<Literal>
<ID>DefaultValue</ID>
<Default>string.Empty</Default>
<ToolTip>Default value of the dependency property</ToolTip>
</Literal>
<Literal>
<ID>CallBackName</ID>
<Default>PropertyCallBackName</Default>
<ToolTip>Name of the callback method that will be triggered when the depencency property has changed</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[public $type$ $PublicName$
{
get { return ($type$)GetValue($PublicName$Property); }
set { SetValue($PublicName$Property, value); }
}
// Using a DependencyProperty as the backing store for $PublicName$. This enables animation, styling, binding, etc...
public static readonly DependencyProperty $PublicName$Property =
DependencyProperty.Register("$PublicName$", typeof($type$), typeof($ParentClassType$), new PropertyMetadata($DefaultValue$, new PropertyChangedCallback($CallBackName$)));
private static void $CallBackName$(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
$ParentClassType$ Changed$ParentClassType$ = (obj as $ParentClassType$);
//TODO: Implement some actions in Changed$ParentClassType$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Espero que os sea tan útil como a mi.Por cierto, podéis encontrar más información sobre cómo crear e importar snippets aquí.
No hay comentarios:
Publicar un comentario