Set readonly at runtime

Nov 17, 2010 at 3:33 PM

Hi again :)

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

        [Category("Name")]
        [ReadOnly(false)]
        public string Name
        {
            get
            {
                return model.Name;
            }
            set
            {
                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?

/Mike

Coordinator
Nov 18, 2010 at 11:16 AM

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

Links:
timheuer.com
silverlightshow.net

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.