title: Silverlight Dependancy Property Change Event Problem
body: <p>I have a custom control that has a Dependancy Property...it has a few but let us say Dragable is my problem. The property is a boolean and I want to execute a piece of code each time it changes...a toggle.</p>
  
  <p>I have two options, both shown below</p>
  
  <pre><code>[Category("Modal Options")]
      public bool Dragable
      {
          get { return (bool)GetValue(DragableProperty); }
          set { SetValue(DragableProperty, value); toggleDragable(); }
      }
  
      // Using a DependencyProperty as the backing store for Dragable.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty DragableProperty =
          DependencyProperty.Register("Dragable", typeof(bool), 
          typeof(PlussWindow), new PropertyMetadata(false));
  
      private void MakeDragable()
      {
          this.dragBehavior.Attach(this.LayoutRoot);
      }
  
      private void MakeUnDragable()
      {
          this.dragBehavior.Detach();
      }
  
      public virtual void toggleDragable()
      {
          if (this.Dragable)
          {
              MakeUnDragable();
          }
          else
          {
              MakeDragable();
          }
      }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>[Category("Modal Options")]
      public bool Dragable
      {
          get { return (bool)GetValue(DragableProperty); }
          set { SetValue(DragableProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for Dragable.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty DragableProperty =
          DependencyProperty.Register("Dragable", typeof(bool), 
          typeof(PlussWindow), new PropertyMetadata(false, (o, e) =&gt; { (o as PlussWindow).toggleDragable(); } 
           ));
  
      private void MakeDragable()
      {
          this.dragBehavior.Attach(this.LayoutRoot);
      }
  
      private void MakeUnDragable()
      {
          this.dragBehavior.Detach();
      }
  
      public virtual void toggleDragable()
      {
          if (this.Dragable)
          {
              MakeUnDragable();
          }
          else
          {
              MakeDragable();
          }
      }
  </code></pre>
  
  <p>Each method results in a 'Object reference not set to an instance of an object'</p>
  
  <p>I usually use binding to get over this problem, e.g Visibility or Text are easily done, but for custom functionality I need to enable this in code.</p>
  
  <p>How do I do this, noting that the propertychanged method is static?</p>