<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CalendarData"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c1calendar="using:C1.Xaml.Calendar"
    xmlns:Xaml="using:C1.Xaml"
    x:Class="CalendarData.CalendarDataDemo"
    mc:Ignorable="d">

    <Page.Resources>
        <DataTemplate x:Key="appointmentTemplate">
            <!-- DataConext is Appointment object -->
            <Border Background="White" HorizontalAlignment="Stretch" Height="24" BorderThickness="1" BorderBrush="Black">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Subject}" Foreground="Black"/>
                </StackPanel>
            </Border>
        </DataTemplate>

        <Style x:Key="appointmentItemStyle" TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Padding" Value="3"/>
        </Style>

        <Style x:Key="listBoxStyle" TargetType="ListBox">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border x:Name="LayoutRoot" Background="{TemplateBinding Background}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
        										Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
        										Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxDisabledForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused"/>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ScrollViewer x:Name="ScrollViewer"
        						Padding="{TemplateBinding Padding}"
        						TabNavigation="{TemplateBinding TabNavigation}"
        						HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
        						HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
        						VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
        						VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
        						IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
        						IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
        						ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"
        						IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
        						BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}">
                                <!-- Important note: 
                                     when application runs in a touch mode, setting ItemsPresenter.ManipulationMode to All 
                                     allows translating manipulations to the C1Calendar,
                                     so that end-user can use horizontal manipulation to navigate C1Calendar to other months. 
                                     But this disables manipulations in the ScrollViewer, 
                                     so that scrolling to invisible appointments is only possible with using vertical ScrollBar.
                                     -->
                                <ItemsPresenter ManipulationMode="All"/>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <local:DaySlotTemplateSelector x:Key="DaySlotTemplateSelector">
            <c1calendar:DaySlotTemplateSelector.Resources>
                <ResourceDictionary>
                    <DataTemplate x:Key="BoldedDay">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <!-- show appointments information saved in the DaySlot.DataSource property -->
                            <TextBlock Grid.Row="0" Text="{Binding Path=DataSource[0].Subject}" FontSize="10" Height="22" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding}" Grid.Row="1" 
                                       Foreground="Plum" HorizontalAlignment="Left" VerticalAlignment="Bottom" FontWeight="SemiBold" Margin="6,0,0,4"/>
                        </Grid>
                    </DataTemplate>
                    <DataTemplate x:Key="UnboldedDay">
                        <TextBlock Text="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="6,22,0,4"/>
                    </DataTemplate>
                </ResourceDictionary>
            </c1calendar:DaySlotTemplateSelector.Resources>
        </local:DaySlotTemplateSelector>
        <DataTemplate  x:Key="BoldedDaySlotTemplate" >
            <Grid>
                <!--ItemsSource is the list of Appointment objects.-->
                <ListBox ItemsSource="{Binding DataSource}" 
							KeyDown="Appointment_KeyDown" 
							Style="{StaticResource listBoxStyle}"
							ItemTemplate="{StaticResource appointmentTemplate}" 
							ItemContainerStyle="{StaticResource appointmentItemStyle}"
							Background="Transparent" 
							HorizontalContentAlignment="Stretch"/>
                <Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"  HorizontalAlignment="Left" VerticalAlignment="Bottom">
                    <TextBlock Text="{Binding}" Margin="5"/>
                </Border>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <c1calendar:C1Calendar x:Name="calendar" ShowWeekNumbers="True" MaxSelectionCount="14" DoubleTapped="calendar_DoubleTapped" 
                               Loaded="cal1_Loaded" DisplayDateChanging="cal1_DisplayDateChanging">
        </c1calendar:C1Calendar>
    </Grid>
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.PrimaryCommands>
                <AppBarButton Icon="Switch" x:Uid="/CalendarDataLib/Resources/Alter" Click="AlterAppearance_Click"/>
                <AppBarButton Icon="Home" x:Uid="/CalendarDataLib/Resources/Today" Click="Today_Click"/>
                <AppBarButton Icon="Help" x:Uid="/CalendarDataLib/Resources/Help" Click="Help_Click"/>
            </CommandBar.PrimaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
</Page>
