title: Dependency Property - Unable to Set Value From XAML
body: <p>I have the following declaration: </p>
  
  <pre><code>public static readonly DependencyProperty PassColorProperty = DependencyProperty.RegisterAttached("PassColor",
              typeof(string),
              typeof(ColorMasking),
              new PropertyMetadata("#FFCCFF"));
  
      public string PassColor
      {
          get { return (string)GetValue(PassColorProperty); }
          set { SetValue(PassColorProperty, value); }
      }
  </code></pre>
  
  <p>At the moment this code does not compile because I haven't added : DependencyProperty to my class.  When I add that code it says that the string PassColor is invalid.</p>
  
  <p>Without the string there at all, the code compiles and I can set read the property from within that class.  I cannot set it from my XAML though.  It says the property doesn't exist.  My xaml is: </p>
  
  <pre><code>&lt;TextBox Grid.Column="1" Grid.Row="8" Margin="3" Width="Auto" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                  b:ColorMasking.Mask=" ... Long Regex Command ... "
                  b:ColorMasking.PassColor="99FF99" /&gt;
  </code></pre>
  
  <p>The code for setting the Mask works perfectly.  I think I have copied all the required stuff too.  It is confusing as to why I cannot add another property.  </p>
  
  <p>If it matters, this is a variation I've written of this code: <a href="https://stackoverflow.com/questions/1103765/how-to-define-textbox-input-restrictions">How to define TextBox input restrictions?</a></p>
  
  <p>EDIT:</p>
  
  <pre><code>public class ColorMasking : DependencyObject
  {
      private static readonly DependencyPropertyKey _maskExpressionPropertyKey = DependencyProperty.RegisterAttachedReadOnly("MaskExpression",
              typeof(Regex),
              typeof(ColorMasking),
              new FrameworkPropertyMetadata());
  
      /// &lt;summary&gt;
      /// Identifies the &lt;see cref="Mask"/&gt; dependency property.
      /// &lt;/summary&gt;
      /// 
      public static readonly DependencyProperty PassColorProperty = DependencyProperty.Register("PassColor",
              typeof(string),
              typeof(ColorMasking),
              new PropertyMetadata("#99FF99"));
  
      public static readonly DependencyProperty FailColorProperty = DependencyProperty.Register("FailColor",
              typeof(string),
              typeof(ColorMasking),
              new PropertyMetadata("#FFCCFF"));
  
      public static readonly DependencyProperty MaskProperty = DependencyProperty.RegisterAttached("Mask",
              typeof(string),
              typeof(ColorMasking),
              new FrameworkPropertyMetadata(OnMaskChanged));
  </code></pre>