Developer

Binding Responses to UI Controls

Bind the OData response to a UI control.

Context

The ODataEntitySet is a major component of the response from SAP Mobile Platform Server. When binding a response to a UI control, keep in mind that:
  • ODataEntitySet represents an OData collection, for example, all BusinessPartners that match a specified criteria.
  • ODataEntitySet is also an IObservableCollection – UI controls bound to the ODataEntitySet are automatically updated when entities are added to or removed from the set.
  • ODataEntity represents a single row of an OData collection. For example, a single BusinessPartner.
  • ODataEntity implements the INotifyPropertyChanged interface.
  • Some helpful methods that operate on ODataEntity include DeepCopy, GetNavigationProperty, and so on.

Procedure

  1. Call ScheduleReadEntitySet method, pass CollectionName as parameter and use Await on the Response property. If an exception is returned, show an error message. If not, cast response.Payload to ODataEntitySet and store in variable <X>.
    // Cast response.Payload to IODataEntitySet and store in variable X
    var execution = Store.ScheduleReadEntitySet(collectionName);
    try
    {
        IODataResponse response = await execution.Response;
        this.EntitySet = (IODataEntitySet)((IODataResponseSingle)response).Payload;
    }
    catch (Exception)
    {
        throw;
    }
  2. At design time or runtime, set the DataContext of the XAML page to the variable <X>. Bind properties of a single entity in the set using the Properties member field (which is also an indexer).
    this.DataContext = SharedContext.Context = new DataContext(); 
    <GridView x:Name="ItemGridView"
    	ItemsSource="{Binding EntitySet}"
    
    <DataTemplate x:Key="Standard250x250ItemTemplate">
    	<TextBlock Text="{Binding Properties[Name].Value}"