Skip to content

Instantly share code, notes, and snippets.

@ugai
Last active July 9, 2022 04:18
Show Gist options
  • Save ugai/63194da110bddd0abb38b08a0d329225 to your computer and use it in GitHub Desktop.
Save ugai/63194da110bddd0abb38b08a0d329225 to your computer and use it in GitHub Desktop.
my propdp snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Define a DependencyProperty</Title>
<Shortcut>propdpng</Shortcut>
<Description>Code snippet for a property using DependencyProperty as the backing store</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property Type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property Name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>ownerclass</ID>
<ToolTip>The owning class of this Property. Typically the class that it is declared in.</ToolTip>
<Function>ClassName()</Function>
<Default>ClassNamePlaceholder</Default>
</Literal>
<!--<Literal>
<ID>defaultvalue</ID>
<ToolTip>The default value for this property.</ToolTip>
<Default>0</Default>
</Literal>-->
</Declarations>
<Code Language="csharp">
<![CDATA[
public $type$ $property$
{
get => ($type$)GetValue($property$Property);
set => SetValue($property$Property, value);
}
public static readonly DependencyProperty $property$Property =
DependencyProperty.Register(nameof($property$), typeof($type$), typeof($ownerclass$), new PropertyMetadata(default($type$)));
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
public class Foo : UserControl
{
public int Bar
{
get => (int)GetValue(BarProperty);
set => SetValue(BarProperty, value);
}
public static readonly DependencyProperty BarProperty =
DependencyProperty.Register(nameof(Bar), typeof(int), typeof(Foo), new PropertyMetadata(default(int)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment