Make Episerver string textbox property wider!

Using UIHint you may choose if a string property should be displayed as a single-line or a multi-line editor. But why is the multi-line editor so wide, and the single-line editor so narrow? We can fix that!

Consider this property definitions:

public virtual string Copyright { get; set; }

[UIHint(UIHint.Textarea)]
public virtual string Description { get; set; }

It produces the following result:
String properties with different width.

If we add an EditorDescriptor like this:

[EditorDescriptorRegistration(TargetType = typeof(string))]
public class StringEditorDescriptor : EditorDescriptor
{
   public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
   {
      // Only target string, not IList<string>
      if (metadata.ContainerType == typeof(string))
      {
         metadata.EditorConfiguration.Add("style", "width: 580px");
      }
      base.ModifyMetadata(metadata, attributes);
   }
}

The updated result:

This code will change the width of all string properties, you may of course control this with antoher UIHint, if you prefer that. To apply for selected properties only, add the UIHint like this:

[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = "widerstring")]

And decorate the properties you want to be wider, like his:

[UIHint("widerstring")]
public virtual string Copyright { get; set; }

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *