3.9 Using dynamic view titles
The base titles of our views are specified as an attribute of the view definition, and were set up for us from the object names when we initially added CRUD operations and views to our model, as shown below.

You can update these static titles, and regenerate the views, but the title of a Details view is also updated dynamically by the Xomega Framework based on the state of the underlying data object. For example, if you create a new sales order, the view title will start with New, and if you make any changes on that screen, then the title will have an asterisk at the end to indicate the modified state, as shown below.

Once you fill in the order details and save it, the title will become the base Sales Order without any asterisk, until you start making additional changes. While this is great functionality that you get right out of the box, which normally requires a lot of tedious coding, you may also want to include additional dynamic information from the view in the title, such as the sales order number for existing sales orders. This could be especially helpful if you can open multiple child windows for different sales orders, such as the case with WPF clients, and need to identify Details views by their titles.
Xomega makes this pretty easy by letting you override the base title in your custom view model, which will make it automatically work for all clients. In order to customize the view model, you need to set the customize attribute on the view’s view model to true, as follows.

Then you need to run the View Models generator under the Presentation Layer folder, open the generated SalesOrderViewModelCustomized.cs file, which will be nested under the corresponding SalesOrderViewModel, and add the override for the base title as follows.

Notice how we append the sales order number to the base title for existing orders using MainObj to reference the main data object for the view. The title will be automatically updated when you save the order, which works for us, since the sales order number is only set once when you save a new sales order. If you need to display the value of another data property in the title, then you may need to subscribe to that data property’s changes in your view model, and then fire a change of the ViewTitle property as a result. But normally, users would not expect the view title to change while you edit the view except for the asterisk at the end, so the default behavior of updating the view title on save should cover most of the cases. The screen below shows how the view title would look after our changes.

Notice that the view became modified when we were entering values in the lookup fields, even though those fields are not really part of the saved data, and were added there just to help the user look up the customer by a store name or a person name. To exclude these fields from affecting the modification state of the data object, we can open the SalesOrderObjectCustomized.cs, and add the following line to the OnInitialized method.

Now, if you make changes only to the lookup fields without touching any other fields, the view title will not show the asterisk, and it won’t prompt you about unsaved changes if you try to close the view.
Next: 3.10 View layout and master-details view >