<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<controls:Page
    x:Class="MUXControlsTestApp.Samples.ItemTemplateDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MUXControlsTestApp.Samples"
    xmlns:controls="http://schemas.modernwpf.com/2019"
    Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}">
    <Page.Resources>
        <controls:RecyclePool x:Key="recyclePool" />
        <controls:StackLayout x:Key="stackLayout" />
    </Page.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        <StackPanel>
            <TextBlock>DataTemplate Sample:</TextBlock>
            <controls:ItemsRepeaterScrollHost
                Height="400"
                Width="150">
                <ScrollViewer>
                    <controls:ItemsRepeater
                        x:Name="repeater0"
                        ItemsSource="{Binding Data}"
                        Layout="{StaticResource stackLayout}">
                        <controls:ItemsRepeater.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" />
                            </DataTemplate>
                        </controls:ItemsRepeater.ItemTemplate>
                    </controls:ItemsRepeater>
                </ScrollViewer>
            </controls:ItemsRepeaterScrollHost>
        </StackPanel>
        <StackPanel Grid.Column="1">
            <TextBlock>DataTemplateSelector Sample:</TextBlock>
            <controls:ItemsRepeaterScrollHost
                Height="400"
                Width="150">
                <ScrollViewer>
                    <controls:ItemsRepeater
                        x:Name="repeater1"
                        ItemsSource="{Binding Data}"
                        Layout="{StaticResource stackLayout}">
                        <controls:ItemsRepeater.ItemTemplate>
                            <local:MySelector>
                                <local:MySelector.TemplateOdd>
                                    <DataTemplate>
                                        <TextBlock
                                            Text="{Binding}"
                                            Foreground="Red" />
                                    </DataTemplate>
                                </local:MySelector.TemplateOdd>
                                <local:MySelector.TemplateEven>
                                    <DataTemplate>
                                        <TextBlock
                                            Text="{Binding}"
                                            Foreground="Green" />
                                    </DataTemplate>
                                </local:MySelector.TemplateEven>
                            </local:MySelector>
                        </controls:ItemsRepeater.ItemTemplate>
                    </controls:ItemsRepeater>
                </ScrollViewer>
            </controls:ItemsRepeaterScrollHost>
        </StackPanel>
        <StackPanel Grid.Column="2">
            <TextBlock>ElementFactory Single Template Sample:</TextBlock>
            <controls:ItemsRepeaterScrollHost
                Height="400"
                Width="150">
                <ScrollViewer>
                    <controls:ItemsRepeater
                        x:Name="repeater2"
                        ItemsSource="{Binding Data}"
                        Layout="{StaticResource stackLayout}">
                        <controls:ItemsRepeater.ItemTemplate>
                            <controls:RecyclingElementFactory RecyclePool="{StaticResource recyclePool}">
                                <controls:RecyclingElementFactory.Templates>
                                    <DataTemplate x:Key="item">
                                        <TextBlock Text="{Binding}" />
                                    </DataTemplate>
                                </controls:RecyclingElementFactory.Templates>
                            </controls:RecyclingElementFactory>
                        </controls:ItemsRepeater.ItemTemplate>
                    </controls:ItemsRepeater>
                </ScrollViewer>
            </controls:ItemsRepeaterScrollHost>
        </StackPanel>
        <StackPanel Grid.Column="3">
            <TextBlock>ElementFactory Multiple Template Sample:</TextBlock>
            <controls:ItemsRepeaterScrollHost
                Height="400"
                Width="150">
                <ScrollViewer>
                    <controls:ItemsRepeater
                        x:Name="repeater4"
                        ItemsSource="{Binding Data}"
                        Layout="{StaticResource stackLayout}">
                        <controls:ItemsRepeater.ItemTemplate>
                            <controls:RecyclingElementFactory
                                RecyclePool="{StaticResource recyclePool}"
                                SelectTemplateKey="OnSelectTemplateKey">
                                <controls:RecyclingElementFactory.Templates>
                                    <DataTemplate x:Key="odd">
                                        <TextBlock
                                            Text="{Binding}"
                                            Foreground="Red" />
                                    </DataTemplate>
                                    <DataTemplate x:Key="even">
                                        <TextBlock
                                            Text="{Binding}"
                                            Foreground="Green" />
                                    </DataTemplate>
                                </controls:RecyclingElementFactory.Templates>
                            </controls:RecyclingElementFactory>
                        </controls:ItemsRepeater.ItemTemplate>
                    </controls:ItemsRepeater>
                </ScrollViewer>
            </controls:ItemsRepeaterScrollHost>
        </StackPanel>
        <StackPanel Grid.Column="4">
            <TextBlock>DataTemplate clear count checking:</TextBlock>
            <controls:ItemsRepeaterScrollHost Height="400" Width="150">
                <ScrollViewer>
                    <controls:ItemsRepeater x:Name="repeater3" 
                                            ItemsSource="{x:Bind Numbers}"
                                            Layout="{StaticResource stackLayout}">
                        <controls:ItemsRepeater.ItemTemplate>
                            <DataTemplate>
                                <local:DisposableUserControl Number="{Bind number, Mode=OneTime}"/>
                            </DataTemplate>
                        </controls:ItemsRepeater.ItemTemplate>
                    </controls:ItemsRepeater>
                </ScrollViewer>
            </controls:ItemsRepeaterScrollHost>
        </StackPanel>
    </Grid>
</controls:Page>
