Install it by simply running Install-Package JOS.PropertyKeyValueList.Ui in the Package manager console.
Inspired by this blogpost by Peter Löfman where he had done something quite similar to what I wanted to achieve so I used his blog post to get started.
The property has two "modes", ReadOnlyKeys or Normal.
Add the property like this to try it out.
[BackingType(typeof(PropertyKeyValueList))]
[KeyValue(typeof(ReadOnlyKeysProvider))]
public virtual IEnumerable<KeyValueItem> ReadOnly { get; set; }ReadOnlyMode is specified by passing in an IReadOnlyKeysProvider to the constructor of the KeyValueAttribute.
IReadOnlyKeysProvider
public interface IReadOnlyKeysProvider
{
List<string> GetKeys();
}My implementation in this example looks like this: ReadOnlyKeysProvider
public class ReadOnlyKeysProvider : IReadOnlyKeysProvider
{
public List<string> GetKeys()
{
return new List<string>()
{
"Arsenal",
"Real Madrid",
"Barcelona",
"Skara FC",
"Axvalls IF",
"Juventus",
"IFK Göteborg",
"Djurgårdens IF",
"AIK"
};
}
}When specifying a IReadOnlyKeysProvider the property will render in ReadOnlyKeysMode and look like this:
The editor will only be able to edit the "value" portion of the property, not the predefined keys. It's not possible to add new items in this mode.
Add the property like this to try it out.
[BackingType(typeof(PropertyKeyValueList))]
[KeyValue]
public virtual IEnumerable<KeyValueItem> NotReadOnly { get; set; }The property will look like this in edit mode:
