Dependency Property - Cannot Set Value from XAML

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); }
    }

This code is not compiling at the moment, because I have not added: DependencyProperty to my class. When I add this code, it says that the PassColor line is invalid.

Without this line, in general, the code compiles, and I can set the reading of a property from this class. However, I cannot install it from my XAML. He says that the property does not exist. My xaml:

<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 up the mask works fine. I think I also copied all the necessary materials. It’s hard to understand why I cannot add another property.

If that matters, this is the option I wrote about this code: How do I determine the input restrictions of a TextBox?

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));
+3
1

, , , AttachedProperty, PassColorProperty DependencyPropery ColorMasking. , . ,

    public static void SetPassColor(DependencyObject obj, string passColor)
    {
        obj.SetValue(PassColorProperty, passColor);
    }

    public static string GetPassColor(DependencyObject obj)
    {
        return (string)obj.GetValue(PassColorProperty);
    }

, MSDN, :

Accessor

GetPropertyName :

Get PropertyName ( )

- . , DockPanel.GetDock UIElement, UIElement.

- . , GetDock Dock, .

AccessOpertyName :

public static void Set PropertyName ( , )

- . , SetDock UIElement, UIElement .

- value . , SetDock Dock, . , - , XAML . - , XAML . , , ( ).

+3

All Articles