In this part of the series we will build the event agenda
- First let’s try to make some room on the UI for the agenda, add a new row to the LayoutRoot grid, make sure that the attendees ListBox has RowSpan=2, then move the DataForm to the lower right cell, we will display the agenda in the upper right cell, Now our home page should look like the following
- To build the agenda let’s recall our data model, we have a table TimeSlot that contains the different time slots in the event, each session is assigned to one time slot and each time slot can have one or more session.
- We will need to retrieve all the time slots along with the sessions in each time slot, to do this go to the RegistrationDomainService.cs file in the RegistrationBooth.Web project, change the GetTimeSlots method as follows
- You will need also to make a small change in the RegistrationDomainService.metadata.cs file, find the TimeSlotMetadata class and add the attribute [Include] to the property Sessions as follows
- Now back to Home.xaml in Visual Studio, from the Data Sources Tool window click the down arrow beside the TimeSlot entity, select “None” for the control used to render this entity as we will create a custom UI to represent this entity, drag and drop the TimeSlot entity on the page, this will create the DomainDataSource control, rename it to timeSlotDomainDataSource
- Switch back to Blend, from the assets tool window add the ItemsControl to the Home.xaml page, place it in the top right cell, rename it to icAgenda.
- Right click the items control, select Auto Size->Fill.
- Right click the items control, select Data bind ItemsSource to Data, in the Create Date Binding dialog box go to the Element Property tab select the timeSlotDomainDataSource element from the left list box and select the Data property from the right list box.
- Right click the items control, select Edit Additional Templates –> Edit Generated Items (ItemTemplate) –> Create Empty.
- In the Create DataTemplate Resource dialog, set the key to timeSlotDataTemplate, click Ok, Blend will switch to the design of the ItemTemplate which initially contain empty grid.
- Use the designer to add a column to the grid as follows
- In the left column add a Rectangle, set the Fill property to white solid color brush, set the RadiusX and RadiusY properties to 10 to have a rounded rectangle, increase the width of the rectangle to overlap the right column (as shown below)
- Add another rectangle to the right column, set the Fill property to white solid color brush, set the RadiusX and RadiusY properties to 10 to have a rounded rectangle, right click the rectangle select Auto Size->Fill, the data template should look like the below image
- In the left column rectangle we will display the time slot start and end times (ex: 09:00 –10:00), to do this add a StackPanel to this column, set the Orientation to Horizontal, in the StackPanel add 3 TextBlocks, set the Text of the middle one to “ – “, set the Text of the first one to a binding to the StartTime property, set the Text of the third one to a binding to the EndTime property, for both bindings use a StringFormat=’HH:mm tt’ to display the time only, the markup for the TextBlocks is shown below
- in the right column we will display all the sessions in the corresponding TimeSlot, to do this add ItemsControl to the right column, name it icSessions, set its ItemsSource property to binding to the Sessions Property.
- Right click the icSessions control, select Edit Additional Templates –> Edit Generated Items (ItemTemplate) –> Create Empty.
- In the Create DataTemplate Resource dialog, set the key to sessionDataTemplate, click Ok, Blend will switch to the design of the ItemTemplate which initially contain empty grid.
- We will create a small template for the session that shows the session title, location and description, so use three textblocks and bind them to the Title and Location and Description properties respectively, the xaml of the sessionDateTemplate is shown below
- Try and run the application, i already have two time slots in my database, the first time slot has two sessions and the second has one session, the UI will look like the following
- As you can see the problem is that the ItemsControl doesn’t provide scrolling, we have to change the Template of the ItemsControl to support this, this is a pretty easy task, right click the icSessions control, select Edit Template-> Create Empty
- In the Create Control Template Resource name it ItemsControlScrollableControlTemplate and click Ok
- Use the following xaml for this template
- We need also to use the same template for the outer ItemsControl (icAgenda), to do this right click the control, select Edit Template-> Apply Resource-> ItemsControlScrollableControlTemplate
- Run the application, you can now scroll both the inner and the outer ItemsControl
See you in the next post
You can download the code from Here