/// <summary>
/// Daniel Balla's Weblog - Various posts
/// on .NET Development, ASP.NET, Agile,
/// TDD, Architecture, SQL and others.
/// </summary>
[Serializable]
class Blog<T> where T : ASP.NET, Ajax, WCF, WF, new()
{
}
Tuesday, September 05, 2006
Dependency property code snippet
As I came across the dependency property (which hit me right when I started developing WinFX) I've created this code snippet to spare me of writting the code every time (the dependency property and the backing property).
You can download it here and then copy it to your Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#\ directory
or you can copy/paste the snippet:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dprop</Title>
<Shortcut>dprop</Shortcut>
<Description>Code snippet for dependancy property and backing property</Description>
<Author>Daniel Balla</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Function>ClassName()</Function>
<Default>ClassNamePlaceholder</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[public static DependencyProperty $property$Property =
DependencyProperty.Register("$property$",
typeof($type$), typeof($classname$));
public $type$ $property$
{
get { return (($type$)base.GetValue($property$Property)); }
set { base.SetValue($property$Property, value); }
}$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
You can download it here and then copy it to your Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#\ directory
or you can copy/paste the snippet:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dprop</Title>
<Shortcut>dprop</Shortcut>
<Description>Code snippet for dependancy property and backing property</Description>
<Author>Daniel Balla</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Function>ClassName()</Function>
<Default>ClassNamePlaceholder</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[public static DependencyProperty $property$Property =
DependencyProperty.Register("$property$",
typeof($type$), typeof($classname$));
public $type$ $property$
{
get { return (($type$)base.GetValue($property$Property)); }
set { base.SetValue($property$Property, value); }
}$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Labels: .net 3

2 Comments:
Great to see you share your snippet. Thanks.
When you install "Orcas" previews, I believe we have a "propdp" snippet which is similar.
Thanks, Rob Relyea
Program Manager, WPF Team
http://rrelyea.spaces.live.com
By
Rob Relyea, at Wednesday, September 6, 2006 10:34:00 AM BST
Indeed, I've installed it a couple days ago and I've seen it now.
Great work!
By
Dani, at Monday, October 2, 2006 10:01:00 PM BST
Post a Comment
<< Home