14. Lookless Controls
Controls have behavior
Visuals separate from implementation
• Defined in Xaml
• Defined by a designer
• Controls usually have a default “style”
17. TemplateBinding
• Template should honor control properties
• Background, Padding, etc.
• TemplateBinding connects properties
• Projects control properties onto the screen
28. List Control Templates
• HeaderTemplate
• FooterTemplate
• ItemTemplate
• ItemContainerStyle
• ItemsPanel
• GroupStyle
• ContainerStyle
• HeaderTemplate
29. List Headers and Footers
• HeaderTemplate displays at top of list
• FooterTemplate displays at bottom of list
• Scroll with list content (not sticky)
Reference:
http://msdn.microsoft.com/en-us/library/windows/apps/hh465319.aspx
39. Grouping Data – KeyedList
- Start with a list of data
- Use a KeyedList class
- Format the data using the following
LINQ query
var groupedItems =
from item in items
orderby item.SortProperty
group item by item.SortProperty into itemsByProperty
select new KeyedList<string, MyObject>(itemsByProperty);
List<KeyedList<string, SampleItem>> KeyedList = groupedItems.ToList();
40. Grouping Data – AlphaKeyGroup
- Start with a list of data
- Create an AlphaKeyGroup class
- Create grouping with:
var alphaKeyGroup = AlphaKeyGroup<SampleItem>.CreateGroups(
items, // basic list of items
(SampleItem s) => { return s.Title; }, // the property to sort
true); // order the items
// returns type List<AlphaKeyGroup<SampleItem>>
41. Grouping Data – CollectionViewSource
• Set DataContext to your page
• Place a CollectionViewSource in the Resources:
<CollectionViewSource
x:Key="ItemsGrouped"
IsSourceGrouped="True"
ItemsPath="InternalList"
Source="{Binding MyKeyedList, Source={Binding}}"/>
<ListView ItemsSource="{Binding Source={StaticResource ItemsGrouped}}" />
49. ContainerContentChanging
Fires when item is realized
Items can be rendered in phases
<ListView ItemTemplate="{StaticResource SampleDataTemplate}"
ContainerContentChanging="IncrementalUpdateHandler" >
private void IncrementalUpdateHandler(ListViewBase sender, ContainerContentChangingEventArgs
args)
{
args.Handled = true;
if (args.Phase != 0)
throw new Exception("we will always be in phase 0");
else
{
// show a placeholder shape
args.RegisterUpdateCallback(ShowText);
}
}
50. ContainerContentChanging
Later phases will be skipped if too much time is needed
private void ShowText(ListViewBase sender, ContainerContentChangingEventArgs args)
{
args.Handled = true;
if (args.Phase != 1)
throw new Exception("we should always be in phase 1");
else
{
// show text from the template
args.RegisterUpdateCallback(ShowImage);
}
}
51. Phase priorities
1. Simple shapes (placeholder visuals)
2. Key text (title)
3. Other text (subtitle)
4. Images
52. Performance tip
Do not use Visibility to show/hide UIElements
this will fire a new ContainerContentChanging event
Instead, use “Opacity=0”