I have the following declaration:
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); }
}
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.
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:
<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" />
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.
If it matters, this is a variation I've written of this code: How to define TextBox input restrictions?
EDIT:
public class ColorMasking : DependencyObject
{
private static readonly DependencyPropertyKey _maskExpressionPropertyKey = DependencyProperty.RegisterAttachedReadOnly("MaskExpression",
typeof(Regex),
typeof(ColorMasking),
new FrameworkPropertyMetadata());
/// <summary>
/// Identifies the <see cref="Mask"/> dependency property.
/// </summary>
///
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));