Adding a Local Property
In this lesson, you will learn how to how to customize a screen by adding a local property.
Adding a Local Property
In addition to using the Screen Designer to customize the controls on a screen, you can also add data items, for example, a local property that can display a calculated value.
To add a local property
In Solution Explorer, double-click the OrdersByCustomers screen.
On the ToolBar Ribbon, click the Add Data Item button.
In the Add Data Item dialog box, select Local Property and then click OK.
A new node named Property1 is added to the left pane of the Screen Designer.
Select the Property1 node and then in the Properties window, select the Name property and type NumberOfOrders.
The name also changes in the left pane of the designer.
Drag the NumberOfOrders node just below the Rows Layout | Details Column node in the center pane.
Press F5 to run the application, and on the navigation menu, click Orders By Customers to display the screen and verify the changes.
Notice that a Number of Orders field is now displayed at the top of the right column, and that no value is displayed.
Click the Close button in the upper-right corner of the application window to close it.
To display a value for a local property
In the left pane of the Screen Designer, select the Customers node.
On the ToolBar Ribbon, in the Write Code list, click Customers_SelectionChanged.
The Code Editor opens and displays the Customers_SelectionChanged method.
In the Customers_SelectionChanged method, add the following code.
NumberOfOrders = Orders.Count.ToString
NumberOfOrders = Orders.Count.ToString();
When a customer is selected, this code calculates the number of orders for that customer. That value is then displayed in the Number of Orders field.
Press F5 to run the application, and on the navigation menu, click Orders By Customers to display the screen and verify the changes.
Notice that when you select a customer, the number of orders for that customer is displayed in the Number of Orders field.
Click the Close button in the upper-right corner of the application window to close it.
Closer Look
This lesson showed how to create a local property to display a calculated value on a screen. In this case, you used the SelectionChanged method of the customers collection to return the Count of orders every time a customer is selected. You may have noticed that the code uses the ToString method to covert the Count to a String. This is required because the local property was defined as a String in the Add Data Item dialog box. If you had instead selected Integer as the type, the conversion would not be required.
In addition to using a local property to display a calculated value, you can also use a local property to collect an input value from the user. For example, you could create a local property that displays a list of cities when a user specifies a geographical region.
Next Steps
In the next lesson, you will learn how to change the layout and appearance of the running application.
Next lesson: Customizing the Running Application
See Also
Tasks
How to: Add a Local Property to a Screen
Walkthrough: Designing a Screen