Define a DependencyProperty for Silverlight application


Snippet Details

Shortcut
propds
Description
Code snippet for a property using DependencyProperty as the backing store and a Handler for the DependencyPropertyChanged event
Language
csharp
Types
Expansion
Author
Fons Sonnemans
Upload on
12/11/2013 2:30:27 PM
Downloads
814

Declarations

ID ToolTip Default
type Property Type object
property Property Name MyProperty
defaultvalue The default value for this property. null
ownerclass The owning class of this Property. Typically the class that it is declared in. ClassNamePlaceholder

Code Output

        #region $property$ Dependency Property

/// <summary> 
/// Get or Sets the $property$ dependency property.  
/// </summary> 
public $type$ $property$ 
{ 
    get { return ($type$)GetValue($property$Property); } 
    set { SetValue($property$Property, value); } 
} 

/// <summary> 
/// Identifies the $property$ dependency property. This enables animation, styling, binding, etc...
/// </summary> 
public static readonly DependencyProperty $property$Property = 
    DependencyProperty.Register("$property$", 
                                typeof($type$), 
                                typeof($ownerclass$), 
                                new PropertyMetadata($defaultvalue$, On$property$PropertyChanged)); 

/// <summary>
/// $property$ changed handler. 
/// </summary>
/// <param name="d">$ownerclass$ that changed its $property$.</param>
/// <param name="e">DependencyPropertyChangedEventArgs.</param> 
private static void On$property$PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
{ 
  var source = d as $ownerclass$; 
  if (source != null) 
  { 
     var value = ($type$)e.NewValue;
     //TODO: Handle new value. 
  }
} 

#endregion $property$ Dependency Property
$end$
    

Download Add to .VSIX Package


comments powered by Disqus

Extension Package

No snippets are added


Languages