<ui:Page
    x:Class="ModernWpf.SampleApp.ControlPages.ListViewPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="http://schemas.modernwpf.com/2019"
    xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
    xmlns:local="clr-namespace:ModernWpf.SampleApp.ControlPages"
    xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    mc:Ignorable="d"
    Loaded="OnLoaded">

    <Page.Resources>
        <local:ContactGroupKeyConverter x:Key="ContactGroupKeyConverter" />

        <CollectionViewSource
            x:Key="ContactsCVS"
            Source="{Binding}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription
                    PropertyName="LastName"
                    Converter="{StaticResource ContactGroupKeyConverter}" />
            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions>
                <cm:SortDescription PropertyName="LastName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <DataTemplate x:Key="ContactListViewTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Ellipse
                    x:Name="Ellipse"
                    Grid.RowSpan="2"
                    Width="32"
                    Height="32"
                    Margin="6"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Fill="Gray" />
                <TextBlock
                    Grid.Column="1"
                    Text="{Binding Name, Mode=OneTime}"
                    Style="{StaticResource BaseTextBlockStyle}"
                    Margin="12,6,0,0" />
                <TextBlock
                    Grid.Column="1"
                    Grid.Row="1"
                    Text="{Binding Company, Mode=OneTime}"
                    Style="{StaticResource BodyTextBlockStyle}"
                    Margin="12,0,0,6" />
            </Grid>
        </DataTemplate>

        <Style TargetType="sc:ControlExample">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Margin" Value="0" />
        </Style>
    </Page.Resources>

    <TabControl
        x:Name="tabControl"
        Style="{StaticResource TabControlPivotStyle}"
        Padding="12,0">
        <TabControl.Resources>
            <Thickness x:Key="PivotItemMargin">12,0,12,20</Thickness>
        </TabControl.Resources>

        <TabItem Header="Basic">
            <sc:ControlExample HeaderText="Basic ListView with Simple DataTemplate">
                <ListView
                    x:Name="listView1"
                    SelectionMode="Single"
                    ItemsSource="{Binding}"
                    VirtualizingPanel.VirtualizationMode="Recycling" />

                <sc:ControlExample.Options>
                    <ui:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
                        <sc:LayoutDensitySelector TargetElement="{Binding Source={x:Reference listView1}}" />
                        <ui:RadioButtons
                            Header="SelectionMode"
                            ItemsSource="{Binding Source={x:Type SelectionMode}, Converter={StaticResource EnumValuesConverter}}"
                            SelectedItem="{Binding Source={x:Reference listView1}, Path=SelectionMode}" />
                        <CheckBox
                            Content="IsEnabled"
                            IsChecked="{Binding Source={x:Reference listView1}, Path=IsEnabled}" />
                    </ui:SimpleStackPanel>
                </sc:ControlExample.Options>
            </sc:ControlExample>
        </TabItem>

        <TabItem Header="Grouped">
            <sc:ControlExample HeaderText="A ListView with Grouped Headers">
                <ListView
                    x:Name="listView2"
                    ItemTemplate="{StaticResource ContactListViewTemplate}"
                    ItemsSource="{Binding Source={StaticResource ContactsCVS}}"
                    VirtualizingPanel.IsVirtualizingWhenGrouping="True"
                    VirtualizingPanel.VirtualizationMode="Recycling">
                    <ListView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock
                                        Text="{Binding Name, Mode=OneTime}"
                                        Style="{DynamicResource TitleTextBlockStyle}" />
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </ListView.GroupStyle>
                </ListView>

                <sc:ControlExample.Options>
                    <ui:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
                        <!--<controls:LayoutDensitySelector TargetElement="{Binding Source={x:Reference listView2}}" />-->
                        <!--<ui:RadioButtons
                                Header="SelectionMode"
                                ItemsSource="{Binding Source={x:Type SelectionMode}, Converter={StaticResource EnumValuesConverter}}"
                                SelectedItem="{Binding Source={x:Reference listView2}, Path=SelectionMode}" />-->
                        <CheckBox
                            Content="IsEnabled"
                            IsChecked="{Binding Source={x:Reference listView2}, Path=IsEnabled}" />
                    </ui:SimpleStackPanel>
                </sc:ControlExample.Options>
            </sc:ControlExample>
        </TabItem>

        <TabItem Header="GridView">
            <sc:ControlExample HeaderText="A ListView that uses a GridView view mode">
                <ListView
                    x:Name="listView3"
                    ItemsSource="{Binding}"
                    VirtualizingPanel.VirtualizationMode="Recycling">
                    <ListView.View>
                        <GridView
                            x:Name="gridView"
                            ColumnHeaderToolTip="Employee Information">

                            <GridViewColumn
                                DisplayMemberBinding="{Binding FirstName, Mode=OneTime}"
                                Header="First Name"
                                Width="120" />

                            <GridViewColumn
                                DisplayMemberBinding="{Binding LastName, Mode=OneTime}"
                                Width="120">
                                <GridViewColumnHeader>
                                    Last Name
                                    <GridViewColumnHeader.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="Ascending" />
                                            <MenuItem Header="Descending" />
                                        </ContextMenu>
                                    </GridViewColumnHeader.ContextMenu>
                                </GridViewColumnHeader>
                            </GridViewColumn>

                            <GridViewColumn
                                DisplayMemberBinding="{Binding Company, Mode=OneTime}"
                                Header="Company"
                                Width="240" />
                        </GridView>
                    </ListView.View>
                </ListView>

                <sc:ControlExample.Options>
                    <ui:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
                        <CheckBox
                            Content="AllowsColumnReorder"
                            IsChecked="{Binding Source={x:Reference gridView}, Path=AllowsColumnReorder}" />
                        <sc:LayoutDensitySelector TargetElement="{Binding Source={x:Reference listView3}}" />
                        <!--<ui:RadioButtons
                                Header="SelectionMode"
                                ItemsSource="{Binding Source={x:Type SelectionMode}, Converter={StaticResource EnumValuesConverter}}"
                                SelectedItem="{Binding Source={x:Reference listView3}, Path=SelectionMode}" />-->
                        <CheckBox
                            Content="IsEnabled"
                            IsChecked="{Binding Source={x:Reference listView3}, Path=IsEnabled}" />
                    </ui:SimpleStackPanel>
                </sc:ControlExample.Options>
            </sc:ControlExample>
        </TabItem>
    </TabControl>
</ui:Page>
