How to: Add a Local Property to a Screen
You can add a field called a local property to a screen. You can use a local property to collect an input value or to display a calculated value.
To create a local property
From the top of the Screen Designer, click Add Data Item….
The Add Data Item dialog box appears.
In the Add Data Item dialog box, select Local Property.
In the Type drop-down list choose a type for the local property.
You can select any of the standard types, such as String, Integer, Email Address, or any of the entities that are associated with your application, such as Customer, Order Detail, or Product.
Select Is Required if you want to require this field to contain a value.
Note
If this field does not contain a value when the user attempts to open the screen, a validation message appears.
In the Name textbox, type a name, and then click OK.
The Add Data Item dialog box will close. The local property appears in the Screen Members List.
To add a local property to a screen
From the Screen Members List, drag the local property onto the desired location of the Screen Content Tree.
In the Screen Content Tree, in the drop-down list that appears next to the local property, select the desired display type.
For example, if you are creating a local property to display a monetary value, you can change its display type to Money Editor or Money Viewer. Likewise, you can display a string local property as either a Text Box or a Label.
To apply validation rules to a local property
In the Screen Members List, select the local property.
From the Properties window, expand the Validation node if it is not already expanded.
The available validation rules will vary depending on the type of the local property.
If the local property must have a value, select Is Required.
Select any other validation rules that you want to apply to the local property.
If you need to perform more complex validation, click Custom Validation.
The Code Editor appears. LightSwitch generates a method named localPropertyName_Validate. You can add custom validation logic to this method. The following example displays an error message if the user enters less than three characters for a local property named CityCode.
Private Sub CityCode_Validate(results As ScreenValidationResultsBuilder) If Me.CityCode.Length < 3 Then results.AddPropertyError("This string must have at least 3 letters.") End If End Sub
partial void CityCode_Validate (ScreenValidationResultsBuilder results) { if (this.CityCode.Length < 3) { results.AddPropertyError("This string must have at least 3 letters."); } }
If the string does not contain at least three characters, the property will be outlined in red and the error message you typed above appears.
To assign a value to a local property by using code
You can set a value to a local property by using code.
The following example sets the value of a local property named ApprovedCheckBox to False.
Private Sub OrdersListDetail_InitializeDataWorkspace _ (saveChangesTo As System.Collections.Generic.List _ (Of Microsoft.LightSwitch.IDataService)) ApproveCheckBox = False End Sub
partial void ApprovedCheckBox_Validate (ScreenValidationResultsBuilder results) { ApprovedCheckBox = false; }
See Also
Tasks
How to: Add a Custom Command to a Screen
How to: Design a Screen by Using the Screen Designer