Social Icons

twitter google plus linkedin rss feed



Dependency Property with Call-back and default value snippet

For me this is the way Microsoft should have created the DependencyProperty snippet from the beginning.
I use this one a lot and it has a placeholder for the default value and the call-back method I am even assigning the instance that called the call-back to a property in the snippet.
<CodeSnippets  xmlns="">
 <CodeSnippet Format="1.0.0">
   <Title>Dependency Property With CallBack</Title>
   <Description>Creates a dependency property with it's callback method</Description>
   <Author>Jose Sanchez</Author>
     <ToolTip>Public name of the depencency property</ToolTip>
     <ToolTip>Type of the property</ToolTip>
     <ToolTip>Type of the parent class of the dependency property</ToolTip>
     <ToolTip>Default value of the dependency property</ToolTip>
     <ToolTip>Name of the callback method that will be triggered when the depencency property has changed</ToolTip>
   <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$
I hope you find it as useful as I do.

By the way, you can find more info about how creating and importing your code snippets here.

No comments:

Post a Comment