-
Notifications
You must be signed in to change notification settings - Fork 711
/
Copy pathItemTemplateDemo.xaml.cs
58 lines (46 loc) · 1.58 KB
/
ItemTemplateDemo.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using RecyclingElementFactory = Microsoft.UI.Xaml.Controls.RecyclingElementFactory;
using SelectTemplateEventArgs = Microsoft.UI.Xaml.Controls.SelectTemplateEventArgs;
namespace MUXControlsTestApp.Samples
{
public sealed partial class ItemTemplateDemo : Page
{
public List<int> Data { get; set; }
public List<MyData> Numbers = new List<MyData>();
public ItemTemplateDemo()
{
Data = Enumerable.Range(0, 1000).ToList();
for(int i=0;i<10;i++)
{
Numbers.Add(new MyData(i));
}
this.InitializeComponent();
}
private void OnSelectTemplateKey(RecyclingElementFactory sender, SelectTemplateEventArgs args)
{
args.TemplateKey = (((int)args.DataContext) % 2 == 0) ? "even" : "odd";
}
}
public class MyData
{
public int number;
public MyData(int number)
{
this.number = number;
}
}
public class MySelector: DataTemplateSelector
{
public DataTemplate TemplateOdd { get; set; }
public DataTemplate TemplateEven { get; set; }
protected override DataTemplate SelectTemplateCore(object item)
{
return (((int)item) % 2 == 0) ? TemplateEven : TemplateOdd;
}
}
}