This project is read-only.

Get an attached property value in custom command

Jun 10, 2011 at 2:35 PM

Is there a way to get the value of an attached property (like "Validation.HasError") in a custom command? We are using Validation attached property in our textboxes and I'm trying to get HasError property to identify if textbox has any validation error. Here's the Custom Command I'm using:


    public class Validation
        private readonly bool _hasError;

        public Validation(System.Windows.Controls.TextBox textBox)
            _hasError = System.Windows.Controls.Validation.GetHasError(textBox);

        public bool HasError
            get { return _hasError; }

I'm getting the following error which makes sense because the property Validation is an attached property.

System.Runtime.Serialization.SerializationException : Error in line 1 position 230. Element '' contains data from a type that maps to the name ''. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'Validation' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.