I am trying to setup a custom attribute in C# to set whether a business object property is editable, eventually enabling or disabling ReadOnly a textbox in XAML. Since (I thought) IsEditable was already implemented in System.Windows.Controls, i thought this would work:
[AttributeUsage(AttributeTargets.Property)]
public class EditableAttribute : Attribute
{
public EditableAttribute(bool isEditable)
{
this.ReadOnly = !isEditable;
}
public virtual bool ReadOnly { get; set; }
}
Well, go figure, it doesn’t. I set [Editable(false)] to a string in an object and it is still editable. I have a feeling I’m not even close. Any help or suggestions would be greatly appreciated!
I am aware this can be setup as a style in xaml, but for this case it needs to be in the business object.
Thanks
You can use BindingDecoratorBase to use custom binding and use an attribute.
The following code is just me modifying my code in my project that uses custom validation . It probably should be refractored.
You can create a custom binding:
And you can use it like:
Xaml: