Original address: http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/ Part-13-styling-tiles-in-the-longlistselector
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
Series Address:http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners
Source code: HTTP://AKA.MS/ABSBEGINNERDEVWP8
PDF version:http://aka.ms/absbeginnerdevwp8pdf
In the previous lesson, we made a lot of progress in associating the new data model with MAINPAGE.XAML, and now we need to focus on the layout of Longlistselector's DataTemplate. We want to tweak each sounddata instance to make them look like tiles instead of rows. So, if we compare the current state of the application user interface with our drawings, the current layout is not reasonable. We'll improve on it in this lesson.
Plan:
We will modify the Longlistselector to take advantage of the grid layout pattern.
We'll completely rewrite each datatemplate to make them more like magnets.
Since we need five to six PivotItem, each pivotitem contains its own longlistselector, there is no need to define a tile layout for each PivotItem, So we're going to abstract them into a set of templates so that all the longlistselector in the MainPage.xaml can use it.
1. Change the longlistselector LayoutMode to Grid
The Longlistselector control contains a LayoutMode property. It accepts the list (default) or grid two enumeration values. By setting LayoutMode to grid and setting the size of cells based on length and height, we can quickly change the appearance of Longlistselector.
By adding lines 49 and 50, the longlistselector looks like this:
Each DataTemplate instance looks like a tile.
2. Modify DataTemplate To create the layout we need
Then we need to modify the DataTemplate to match the layout we want. I'll highlight and delete the contents of the DataTemplate:
Then I'll start with a grid of only one cell. In grid, I will use TextBlock to display the name of the sound at the bottom of the tile. I'm going to surround it with a stackpanel so I can set its vertical position later in the grid cell. So I added the following code to the DataTemplate: