In Sivlerlight, the concept of a Value Converter is present to help a Control "adjust" the Data coming in from the Source before it gets displayed on the UI layer. In LightSwitch, value converters are not present. Until LightSwitch team decides to allow us to specify not only the Data Binding property but also a Converter instance, the below workaround could help.
The snapshot below represents a "List and Details Screen" for an Appointment Entity together with the Appointment Items related:

The "List and Details Screen" displays a list of "All Appointments" stored in the Database. Upon selecting a single Appointment, the Appointment Details + Appointment Items are also shown.
Point A: Represents the "Category" field of the Selected Item on screen.
Point B: Represents a "Data Item" (As LightSwitch calls it) added to the screen. In other words, it is just a Property on the screen.
Point C: A data field placed on the screen details section to show the "Category" of the selected Appointment.
Originally, "Category" property in Point C is bound to "Category" field in Point A. This means, whatever is being stored in "Category" field in the Database for a single Appointment, it will automatically show on screen. However, there are some occasions where we want to:
- Concatenate text as both "Suffix" or "Prefix" to the Data coming from the Database
- Do a checking if source data is empty to display "Empty" or "None" etc ...
- etc ...
As was mentioned at the beginning of this post, there is no Value Converters in LightSwitch to do the job of manipulating the source data before showing it on screen. Hence, the Screen Property workaround!
The solution goes as follows:
- Define a new Property on screen (adding a new Data Item) call it "Category" as shown in Point B
- Bind the field "Category" in Point C to property "Category" in Point B
- Implement the InitializeDataWorkspace method. This method is called just before the screen data is retrieved. In the body of this method, initialize the "Category" property on screen to whatever value you prefer. In our case "None".
- Implement the Appointments' Query SelectionChanged event handler. This handles the event of changing selection in the list of "Appointments" on screen.
"Show me the green" :). The code follows:
partial void AllAppointments_InitializeDataWorkspace(List<IDataService> saveChangesTo)
{
// Initialize the property to "None"
this.Category = "None";
}
partial void Appointments_SelectionChanged()
{
// If there is no SelectedItem return
if (this.Appointments.SelectedItem == null)
return;
// Initialize Category to whatever is returned from Database
this.Category = this.Appointments.SelectedItem.Category;
// If the data stored in Database is Null or Empty, then set the Category property
// value to "None"
if (String.IsNullOrEmpty(this.Appointments.SelectedItem.Category))
{
this.Category = "None";
}
}
The code is self-explanatory.
That's it. When the screen loads, if the "Category" field of the SelectedItem i.e. selected Appointment is Null or Empty, it gets displayed by a value of "None".
HTH,
Best Regards
Tags: LightSwitch, Silverlight, Visual Studio