Set readonly at runtime

Nov 17, 2010 at 4:33 PM

Hi again :)

So this time I'm trying to change the readonlyattribute of a property:

        public string Name
                return model.Name;
                model.Name = value;


I would like to be able to set [Readonly] to true (After I hit the Save-button) at runtime.

I looked around a bit and found some solutions involvning the TypeDescriptor class, but it seems like Silverlight is lacking this class.

Do you know how to solve this?


Nov 18, 2010 at 12:16 PM

It sounds like you may be using this as a data entry form? If so I recommend using a DataForm.


Otherwise, you would have to modify the logic where it checks the readonly attribute. Example would be to see if the property value is dirty and if it is, then consider it writable, otherwise readonly. Then implement your own IsDirty interface. You should also make a custom attribute so you don't break the default readonly processing and put your logic infront of it.