Share via


Exercise 3: Display the Query Results in the Silverlight User Interface

In this exercise you will modify the existing Silverlight application to display the list of products and product details of the currently selected product.

Task 1 – Modifying the Exiting Silverlight User Interface to Display the Query Results.

  1. Right-click GetItemsViewModel.cs file in Solution Explorer and select Open.
  2. Use snippet 4.4.7 to add the ITEM_DETAIL_CMD constant to the list of constants. The ITEM_DETAIL_CMD defines the Rest Url format used to retrieve the details of an item.

    Figure 24

    ITEM_DETAIL_CMD constant

  3. Use snippet 4.4.8 to add the body to the existing GetDetails method. This method creates an asynchronous http GET request for the formatted Rest Url.

    Figure 25

    GetDetails method

  4. Use snippet 4.4.9 to create the body of the existing DetailsResponseCallBack method. This method receives the results as xml. The Actual Sales Price and Profit Margin values are calculated in the workbook using formulas. The Excel Rest query retrieves the calculated values. The method then updates the CurrentItem object with the new values. The user interface is configured with two-way data binding and displays the changes. Notice the use of the Dispatcher when updating the Items property. This is required because the UI consumes the collection.

    Figure 26

    DetailsResponseCallback method

  5. Use snippet 4.4.9 to initialize the ViewModel reference and set the application’s DataContext.

    Figure 27

    MainPage method

Task 2 – Deploying and Testing the Silverlight Application.

  1. Right-click on the SharePoint.Client.ExcelRest project in Solution Explorer and select Set as StartUp Project.
  2. Press F5 to build and deploy.
  3. Use Internet Explorer to navigate to https://intranet.contoso.com/ExcelRestDemo.aspx
  4. Click the Product drop down and select a product. Notice the details display in the application as the product is selected. The details are retrieved from the Workbook each time the Product dropdown is changed.

    Figure 28

    Product screen

  5. Modify the Discount value. Notice the Profit Margin does not change values.
  6. Click the Download Workbook link. The download link is a rest Url requesting the data in workbook format.