You are not logged in. Log in

The EntityPresenter (Part 4 of 6)

This part of the tutorial will show you how you can use the EntityPresenter control that comes with Vidyano. We will show the data from a Customer entity on the CustomerEdit page we created in the previous part of the tutorial series.

In order for the new page to be able to get a Customer entity as parameter, we need to add a constructor to the CustomerEdit page controller.

Passing and exposing a Customer entity on the CustomerEdit page controller

  1. In the AdventureWorksDemo.Module project, under Customers, PageControllers, double-click the CustomerEdit.cs file to open the code editor.
  2. Add a property of type Customer to the class:
    public Customer CustomerEntity { get; private set; }

  3. Update the constructor to accept the entity and set the property:

  4. public CustomerEdit(Customer ce)
     {
          CustomerEntity = ce;
     
          this.InitializeComponent();
          // Initialization code goes here
     }

  5. Open the XAML editor of the Overview page in the AdventureWorksDemo.Module.View project (Overview.xaml), and update the Button tag to include the CommandParameter attribute:

  6. <Button HorizontalAlignment="Right" Height="30" Margin="0, 10, 0, 0" 
             Width="75" Content="Edit"
             Command="{vi:OpenPage CustomerEdit}"
             CommandParameter="{Binding SelectedItem, ElementName=PART_2}" />

    Note: This will pass the current selected item from the ListView on the OverviewPage to the CustomerEdit page being opened.

Visualising the entity

Now that we have the entity exposed as a property on the CustomerEdit page controller, we will visualize it using the EntityPresenter control.

  1. Open the Customer module by double-clicking Customers.mod in the AdventureWorksDemo.Module project.
  2. On the Pages tab, select the CustomerEdit page from the list at the top.
  3. This page has only one part, click the 1 button in the center of PART_1.
  4. From the Add Part for PART_1 dialog, select the EntityPresenter.
  5. Select the Customer entity from the entity list and the CustomerEntity as Binding. Then select some of its properties as shown in the screenshot below and click Next.


    Figure 22 : Configuring the EntityPresenter

Launching the application

  1. Run the application by pressing CTRL+F5 or the Play button on the toolbar.
  2. In the application, click the Customers module and select Overview page.
  3. Select a customer from the list.
  4. Click the Edit button on the bottom right. This will open the CustomerEdit page, this time showing the customer you selected in the previous step.


    Figure 23 : The Customer being shown using the EntityPresenter

Fine-tuning: Configuring the module’s startup page

Since we now always need a Customer entity when opening the CustomerEdit, it no longer makes sense to have it listed as an entry point. As you may have noticed, the CustomerEdit page doesn’t have its Entry Point checked on the page editor. So why is it an entry point? The correct answer is, it isn’t. Then why does the CustomerEdit page show up when we click on the module in the application? The answer is: because there are no entry points set at all for this module. When Vidyano detects that none of the pages are set as entry point, every page is a possible entry point. From the moment one or more pages in the module are set as Entry Point, only those pages will be shown.

To fix this in our current module, we just need to flag the Overview page as Entry Point, thereby ensuring that only that page can be used as an entry point at this time. To do this:

  1. Open the Customer module by double-clicking Customers.mod in the AdventureWorksDemo.Module project.
  2. On the Pages tab, select the Overview page from the list at the top.
  3. Click on the Entry Point checkbox to flag this page as an entry point.


    Figure 24 : Flagging a page as Entry Point

 
Visual Studio 2010 partner logo
Rhea