Customizing Field Definitions
At some point you will need to modify the properties of field definition objects after they have been created, for example to set a maximum length of a text field or the Filter property of a file picker. The
ModelObjectFormDefiner class has an event for just this purpose. The DidCreateFieldDefinition event is fired when a field definition object has been obtained from
FieldDefinitionRegistry, and provides the field definition object within the event arguments object. By handling this event you get a chance to change the properties of each field definition.
You'll need to cast the object to the correct type - here's an example which sets the
Filter property of any
FilePickerFieldDefinition objects that are created:
if (e.FieldDefinition is FilePickerFieldDefinition)
{
FilePickerDefinition def = e.FieldDefinition as FilePickerDefinition;
def.Filter = "*.doc|Document Files";
}
You can also check the PropertyName property to customize the definitions for specific properties:
if (e.FieldDefinition is FilePickerFieldDefinition and e.PropertyName.Equals("DocumentFilename"))
{
FilePickerDefinition def = e.FieldDefinition as FilePickerDefinition;
def.Filter = "*.doc|Document Files";
// We can change the Title, too:
def.Title = "Document file";
}