<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:CustomGroupingView" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/C1.Silverlight.Schedule.5;component/themes/generic.xaml" />

    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="ItemsControl">
        <Setter Property="Padding" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ItemsControl">
                    <Border Background="{TemplateBinding Background}">
                        <ItemsPresenter />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- determines the template used for displaying group headers -->
    <DataTemplate x:Key="GroupHeaderTemplate">
        <Grid>
            <c1:C1BrushBuilder x:Name="Background" Style="{StaticResource C1Scheduler_ControlArea_BrushStyle}" Input="{Binding Background}" />
            <c1:C1BrushBuilder x:Name="BorderBrush" Style="{StaticResource C1Scheduler_MonthHeaderForeground_BrushStyle}" Input="{Binding Path=Scheduler.Background}" />
            <Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="0,0,1,0" BorderBrush="{Binding Output, ElementName=BorderBrush}" Background="{Binding Output, ElementName=Background}">
                <TextBlock Foreground="{Binding Path=Scheduler.Foreground}" Margin="0" TextWrapping="Wrap" Text="{Binding DisplayName}" VerticalAlignment="Center" HorizontalAlignment="Center" />
            </Border>
        </Grid>
    </DataTemplate>

    <!-- Defines a style for previous/next appointment navigation pane (containing 
		next/previous labels) represented by ContentControl. -->
    <Style x:Key="C1Scheduler_PrevNextAppPane_Style" TargetType="ContentControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ContentControl">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <c1:C1BrushBuilder x:Name="BackgroundBrush" Style="{StaticResource C1Scheduler_NavPane_Style}" Input="{TemplateBinding Background}" />
                        <c1:C1BrushBuilder x:Name="MouseOverBrush" Style="{StaticResource C1Scheduler_NavPane_HoverStyle}" Input="{TemplateBinding Background}" />
                        <c1:C1LayoutTransformer Grid.Row="1" Grid.Column="0">
                            <c1:C1LayoutTransformer.LayoutTransform>
                                <RotateTransform Angle="-90" />
                            </c1:C1LayoutTransformer.LayoutTransform>
                            <Button Content="{Binding PreviousAppointmentText}" c1:CommandExtensions.CommandTarget="{Binding  DataContext, RelativeSource={RelativeSource TemplatedParent}}" c1:CommandExtensions.Command="c1:C1Scheduler.NavigateToPreviousAppointmentCommand" Background="{Binding Output, ElementName=BackgroundBrush}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}" Tag="{Binding Output, ElementName=MouseOverBrush}" Foreground="{Binding Foreground}" Style="{StaticResource C1Scheduler_PreviousButton_Style}" />
                        </c1:C1LayoutTransformer>
                        <c1:C1LayoutTransformer Grid.Row="1" Grid.Column="2">
                            <c1:C1LayoutTransformer.LayoutTransform>
                                <RotateTransform Angle="-90" />
                            </c1:C1LayoutTransformer.LayoutTransform>
                            <Button Content="{Binding NextAppointmentText}" c1:CommandExtensions.CommandTarget="{Binding  DataContext, RelativeSource={RelativeSource TemplatedParent}}" c1:CommandExtensions.Command="c1:C1Scheduler.NavigateToNextAppointmentCommand" Background="{Binding Output, ElementName=BackgroundBrush}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}" Tag="{Binding Output, ElementName=MouseOverBrush}" Foreground="{Binding Foreground}" Style="{StaticResource C1Scheduler_NextButton_Style}" />
                        </c1:C1LayoutTransformer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <local:IsTodayVisibilityConverter x:Key="IsTodayVisibilityConverter" />
    
    <!-- determines the style of the day group in a day view -->
    <Style TargetType="ItemsControl" x:Key="DayGroup_Style">
        <Setter Property="Margin" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ItemsControl">
                    <Grid>
                        <Border BorderThickness="1,0,0,0" x:Name="border" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}, ConverterParameter=Invert}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}">
                            <ItemsPresenter />
                        </Border>
                        <Border BorderThickness="2,0,1,0" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}}" BorderBrush="{Binding Path=Scheduler.TodayBackground}">
                            <ItemsPresenter />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- determines the style used for the day header button in all views -->
    <Style TargetType="Button" x:Key="DayHeaderButtonStyle">
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TodayMouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <c1:C1BrushBuilder x:Name="BackgroundBrush" Style="{StaticResource C1Scheduler_DayHeader_Style}" Input="{Binding Path=OwnerGroup.Background}" />
                        <c1:C1BrushBuilder x:Name="MouseOverBrush" Style="{StaticResource C1Scheduler_DayHeader_HoverStyle}" Input="{Binding Path=OwnerGroup.Background}" />
                        <c1:C1BrushBuilder x:Name="TodayMouseOverBrush" Style="{StaticResource C1Scheduler_TodayHeader_HoverBrushStyle}" Input="{Binding Path=Scheduler.TodayBackground}" />
                        <Border BorderThickness="{TemplateBinding BorderThickness}" x:Name="DayHeaderBorder" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}, ConverterParameter=Invert}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}" Background="{Binding ElementName=BackgroundBrush, Path=Output}" VerticalAlignment="Stretch">
                            <Border x:Name="MouseOverElement" Background="{Binding ElementName=MouseOverBrush, Path=Output}" VerticalAlignment="Stretch" Visibility="Collapsed" />
                        </Border>
                        <Border BorderThickness="{TemplateBinding BorderThickness}" x:Name="TodayHeaderBorder" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}}" BorderBrush="{Binding Scheduler.TodayBackground}" Background="{Binding Scheduler.TodayBackground}" VerticalAlignment="Stretch">
                            <Border x:Name="TodayMouseOverElement" Background="{Binding ElementName=TodayMouseOverBrush, Path=Output}" VerticalAlignment="Stretch" Visibility="Collapsed" />
                        </Border>
                        <ContentPresenter Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Center" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- determines the style used for displaying time slots in a Day view.
         Copy it into every theme, as using StaticResource here affects performance -->
    <c1:TimeSlotStyleSelector x:Key="TimeSlotStyleSelector">
        <!-- Don't use selection states. With selection states multiple selection works incorrectly. -->
        <c1:TimeSlotStyleSelector.Resources>
            <ResourceDictionary>
                <Style x:Key="C1Scheduler_WorkSlot_Style" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="BorderBrush" Value="{StaticResource C1Scheduler_WorkHourLightBorder_Brush}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="c1:VisualIntervalPresenter">
                                <Grid>
                                    <Border BorderThickness="0,0,1,0" x:Name="border" IsHitTestVisible="False" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}, ConverterParameter=Invert}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}">
                                        <Border Background="{Binding Path=Scheduler.AlternatingBackground}" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}">
                                            <Border Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                        </Border>
                                    </Border>
                                    <Border BorderThickness="0,0,1,0" IsHitTestVisible="False" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}}" BorderBrush="{Binding Path=Scheduler.TodayBackground}">
                                        <Border Background="{Binding Path=Scheduler.AlternatingBackground}" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}">
                                            <Border Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                        </Border>
                                    </Border>
                                    <ContentPresenter Content="{TemplateBinding Content}" Margin="0,1,1,0" ContentTemplate="{TemplateBinding ContentTemplate}" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

                <Style x:Key="C1Scheduler_TopWorkSlot_Style" BasedOn="{StaticResource C1Scheduler_WorkSlot_Style}" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="BorderBrush" Value="{StaticResource C1Scheduler_WorkHourBorder_Brush}" />
                </Style>

                <Style x:Key="C1Scheduler_FreeSlot_Style" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="BorderBrush" Value="{StaticResource C1Scheduler_FreeHourLightBorder_Brush}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="c1:VisualIntervalPresenter">
                                <Grid>
                                    <Border BorderThickness="0,0,1,0" x:Name="border" IsHitTestVisible="False" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}, ConverterParameter=Invert}" BorderBrush="{StaticResource C1Scheduler_Border_Brush}">
                                        <Border Background="{StaticResource C1Scheduler_FreeHour_Brush}" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}">
                                            <Border Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                        </Border>
                                    </Border>
                                    <Border BorderThickness="0,0,1,0" IsHitTestVisible="False" Visibility="{Binding StartTime, Mode=OneTime, Converter={StaticResource IsTodayVisibilityConverter}}" BorderBrush="{Binding Path=Scheduler.TodayBackground}">
                                        <Border Background="{StaticResource C1Scheduler_FreeHour_Brush}" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}">
                                            <Border Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                        </Border>
                                    </Border>
                                    <ContentPresenter Content="{TemplateBinding Content}" Margin="0,1,1,0" ContentTemplate="{TemplateBinding ContentTemplate}" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

                <Style x:Key="C1Scheduler_TopFreeSlot_Style" BasedOn="{StaticResource C1Scheduler_FreeSlot_Style}" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="BorderBrush" Value="{StaticResource C1Scheduler_FreeHourBorder_Brush}" />
                </Style>

            </ResourceDictionary>
        </c1:TimeSlotStyleSelector.Resources>
    </c1:TimeSlotStyleSelector>

    <!-- determines the style used for displaying All-Day area in a Day view -->
    <c1:DayIntervalStyleSelector x:Key="AllDayAreaStyleSelector">
        <c1:DayIntervalStyleSelector.Resources>
            <ResourceDictionary>
                <Style x:Key="C1Scheduler_Day_Style" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="c1:VisualIntervalPresenter">
                                <Grid>
                                    <c1:C1BrushBuilder x:Name="SelectedBrush" Style="{StaticResource C1Scheduler_AllDayAreaSelected_Style}" Input="{Binding Path=OwnerGroup.Background}" />
                                    <Border x:Name="AllDayBorder" Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="0,1,1,2" BorderBrush="{StaticResource C1Scheduler_Border_Brush}" IsHitTestVisible="False">
                                        <Border x:Name="SelectedElement" Background="{Binding ElementName=SelectedBrush, Path=Output}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    </Border>
                                    <Border Background="{Binding Path=VisualIntervals[0].StatusBrush}" Opacity="0.2" Margin="0,1,1,2" c1:CoverElementsPane.Orientation="Horizontal" c1:CoverElementsPane.PaneName="allDayPane" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

                <Style x:Key="C1Scheduler_Today_Style" TargetType="c1:VisualIntervalPresenter">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="c1:VisualIntervalPresenter">
                                <Grid>
                                    <c1:C1BrushBuilder x:Name="SelectedBrush" Style="{StaticResource C1Scheduler_AllDayAreaSelected_Style}" Input="{Binding Path=OwnerGroup.Background}" />
                                    <Border x:Name="AllDayBorder" Background="{Binding Path=Owner.Tag, RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="0,1,1,2" IsHitTestVisible="False" BorderBrush="{Binding Path=Scheduler.TodayBackground}">
                                        <Border x:Name="SelectedElement" Background="{Binding ElementName=SelectedBrush, Path=Output}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    </Border>
                                    <Border Background="{Binding Path=VisualIntervals[0].StatusBrush}" Opacity="0.2" Margin="0,1,1,2" c1:CoverElementsPane.Orientation="Horizontal" c1:CoverElementsPane.PaneName="allDayPane" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ResourceDictionary>
        </c1:DayIntervalStyleSelector.Resources>
    </c1:DayIntervalStyleSelector>

    <!-- Style that represents One Day View -->
    <Style x:Key="OneDayStyle" TargetType="c1:C1Scheduler" BasedOn="{StaticResource BaseViewStyle}">
        <Setter Property="c1:C1Scheduler.VisualIntervalScale" Value="00:30:00" />
        <Setter Property="ShowWorkTimeOnly" Value="false" />
        <Setter Property="c1:C1Scheduler.Template">
            <Setter.Value>
                <ControlTemplate TargetType="c1:C1Scheduler">
                    <Border Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ControlBackground}" BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}" BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}" UseLayoutRounding="False">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <!-- DayHeader grid (includes day headers) -->
                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="57" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="17" />
                                </Grid.ColumnDefinitions>
                                <!-- hidden SchedulerPresenters for each group (they should generate VisualIntervals) -->
                                <ItemsControl Height="0" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=VisibleGroupItems}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <c1:C1SchedulerPresenter />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <ItemsControl Grid.Column="1" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=VisibleGroupItems[0].VisualIntervalGroups}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <c1:C1UniformGrid Rows="1" Background="{StaticResource C1Scheduler_Border_Brush}" />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                </Grid.RowDefinitions>
                                                <Button x:Name="dayHeaderButton" Grid.Row="0" MinHeight="25" Padding="0,2,0,2" Style="{StaticResource DayHeaderButtonStyle}" Foreground="{Binding Path=Scheduler.Foreground}" Content="{Binding Converter={StaticResource VisualIntervalToStringConverter},                   ConverterParameter=DayViewDayHeaderFormat}" c1:CommandExtensions.CommandParameter="{Binding Path=Scheduler.OneDayStyle}" c1:CommandExtensions.Command="c1:C1Scheduler.ChangeStyleCommand" />
                                                <ItemsControl x:Name="GroupHeaderList" Grid.Row="1" HorizontalAlignment="Stretch" Style="{StaticResource DayGroup_Style}" Visibility="{Binding Path=Scheduler.IsGrouped, Converter={StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding Path=Scheduler.VisibleGroupItems}" Background="{Binding Path=OwnerGroup.Background}">
                                                    <ItemsControl.ItemTemplate>
                                                        <DataTemplate>
                                                            <!-- Group Header  -->
                                                            <ContentControl MinHeight="25" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ContentTemplate="{Binding Scheduler.GroupHeaderTemplate}" Content="{Binding}" />
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                    <ItemsControl.ItemsPanel>
                                                        <ItemsPanelTemplate>
                                                            <c1:C1UniformGrid Rows="1" />
                                                        </ItemsPanelTemplate>
                                                    </ItemsControl.ItemsPanel>
                                                </ItemsControl>
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <Border Grid.Column="2" />
                            </Grid>
                            <!-- AllDay area grid (should scroll vertically) -->
                            <ScrollViewer Grid.Row="1" Height="54" BorderThickness="0" Padding="0" Background="Transparent" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="57" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <ItemsControl Grid.Column="1" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},               Path=VisibleGroupItems[0].VisualIntervalGroups}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <c1:C1UniformGrid Rows="1" Background="{StaticResource C1Scheduler_Border_Brush}" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <ItemsControl ItemsSource="{Binding Path=Scheduler.VisibleGroupItems}" Style="{StaticResource DayGroup_Style}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <c1:C1UniformGrid Rows="1" />
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <Grid>
                                                                    <local:ItemsSourceRetriever x:Name="isr" Parameter="Self" SchedulerGroup="{Binding}" />
                                                                    <c1:VisualIntervalGroupsPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{Binding Background}" ItemsSource="{Binding ItemsSource, ElementName=isr}" ItemContainerStyleSelector="{StaticResource AllDayAreaStyleSelector}">
                                                                        <c1:VisualIntervalGroupsPresenter.PanelTemplate>
                                                                            <DataTemplate>
                                                                                <c1:C1UniformGrid Rows="1" />
                                                                            </DataTemplate>
                                                                        </c1:VisualIntervalGroupsPresenter.PanelTemplate>
                                                                    </c1:VisualIntervalGroupsPresenter>
                                                                    <c1:AppointmentsCoverPane x:Name="allDayPane" Owner="{Binding Owner}" UseSimpleLayout="false" c1:AppointmentsCoverPane.AppointmentFilter="Event" IsDragDropDisabled="{Binding Path=Scheduler.IsDragDropDisabled}" ExtendOnOverflow="True" CoverElementsMargin="10">
                                                                        <c1:AppointmentsCoverPane.Resources>
                                                                            <ResourceDictionary>
                                                                                <Thickness x:Key="TimeBorderThickness">0</Thickness>
                                                                            </ResourceDictionary>
                                                                        </c1:AppointmentsCoverPane.Resources>
                                                                    </c1:AppointmentsCoverPane>
                                                                </Grid>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Grid>
                            </ScrollViewer>
                            <!-- TimeSlots grid (should scroll vertically) -->
                            <ScrollViewer x:Name="scrollViewer" Grid.Row="2" BorderThickness="0" Padding="0" MaxHeight="100000" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="57" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <ItemsControl Grid.Column="0" x:Name="HourMarkersList" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},            Path=VisibleGroupItems[0].VisualIntervalGroups[0].VisualIntervals}" ItemTemplate="{StaticResource C1Scheduler_TimeRuler_Template}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <c1:C1UniformGrid Columns="1" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                    </ItemsControl>
                                    <ItemsControl Grid.Column="1" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},                Path=VisibleGroupItems[0].VisualIntervalGroups}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <c1:C1UniformGrid Rows="1" Background="{StaticResource C1Scheduler_Border_Brush}" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <ItemsControl ItemsSource="{Binding Path=Scheduler.VisibleGroupItems}" Style="{StaticResource DayGroup_Style}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <c1:C1UniformGrid Rows="1" />
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <Grid UseLayoutRounding="False">
                                                                    <c1:C1BrushBuilder x:Name="selectedBackground" Style="{StaticResource C1Scheduler_TimeSlotSelected_BrushStyle}" Input="{Binding Background}" />
                                                                    <local:ItemsSourceRetriever x:Name="isr" Parameter="VisualIntervals" SchedulerGroup="{Binding}" />
                                                                    <c1:VisualIntervalsPresenter x:Name="presenter" ItemContainerStyleSelector="{StaticResource TimeSlotStyleSelector}" ItemsSource="{Binding ItemsSource, ElementName=isr}" ItemTemplate="{Binding Path=Scheduler.VisualIntervalTemplate}" Background="{Binding Background}" Tag="{Binding Output, ElementName=selectedBackground}">
                                                                        <c1:VisualIntervalsPresenter.PanelTemplate>
                                                                            <DataTemplate>
                                                                                <c1:C1UniformGrid Columns="1" />
                                                                            </DataTemplate>
                                                                        </c1:VisualIntervalsPresenter.PanelTemplate>
                                                                    </c1:VisualIntervalsPresenter>
                                                                    <c1:AppointmentsCoverPane x:Name="appPane" Owner="{Binding Owner}" UseSimpleLayout="false" SizingType="Proportional" c1:AppointmentsCoverPane.AppointmentFilter="Appointment" IsDragDropDisabled="{Binding Path=Scheduler.IsDragDropDisabled}" CoverElementsMargin="10">
                                                                        <c1:AppointmentsCoverPane.Resources>
                                                                            <ResourceDictionary>
                                                                                <Thickness x:Key="TimeBorderThickness">5,0,0,0</Thickness>
                                                                            </ResourceDictionary>
                                                                        </c1:AppointmentsCoverPane.Resources>
                                                                    </c1:AppointmentsCoverPane>
                                                                </Grid>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                    <!-- next/previous appointment navigation pane -->
                                    <!-- can't use standard canvas here as SL doesn't support binding to ActualWidth -->
                                    <!-- use StretchingCanvas which sets child's width to the own ActualWidth value -->
                                    <c1:StretchingCanvas Grid.Column="1">
                                        <ContentControl c1:StretchingCanvas.Left="0" c1:StretchingCanvas.Top="{Binding VerticalOffset, ElementName=scrollViewer}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" Height="{Binding ViewportHeight, ElementName=scrollViewer}" Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource C1Scheduler_PrevNextAppPane_Style}" Visibility="{Binding HasVisibleAppointments, RelativeSource={RelativeSource TemplatedParent},                                                              Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Invert}" />
                                    </c1:StretchingCanvas>

                                </Grid>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="c1:C1Scheduler.VisualIntervalGroupDescriptions">
            <Setter.Value>
                <c1:IntervalGroupDescriptionCollection>
                    <c1:VisualIntervalGroupDescription PropertyName="StartTime.Date" />
                </c1:IntervalGroupDescriptionCollection>
            </Setter.Value>
        </Setter>
        <Setter Property="c1:C1Scheduler.VisualIntervalPanel">
            <Setter.Value>
                <DataTemplate>
                    <c1:C1UniformGrid Columns="1" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="c1:C1Scheduler.VisualTimeSpan" Value="1" />
        <Setter Property="c1:C1Scheduler.VisualIntervalTemplate">
            <Setter.Value>
                <DataTemplate>
                    <!-- don't place C1BrushBuilder here, it affects performance, use binding to the relative ancestor instead -->
                    <Border Background="{Binding Path=StatusBrush}" Opacity="0.2" c1:CoverElementsPane.Orientation="Vertical" c1:CoverElementsPane.PaneName="appPane" MinHeight="20" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="WeekStyle" TargetType="c1:C1Scheduler" BasedOn="{StaticResource OneDayStyle}">
        <Setter Property="VisualTimeSpan" Value="7" />
    </Style>

    <Style x:Key="WorkingWeekStyle" TargetType="c1:C1Scheduler" BasedOn="{StaticResource OneDayStyle}">
        <Setter Property="VisualTimeSpan" Value="7" />
    </Style>

</ResourceDictionary>