<?xml version="1.0" encoding="utf-8"?>

<!--
This is the master template for standard menu screens:
A header text, left the menu, under the menu a small video preview,
at the right side the content pane and at the bottom the current play control.

Usage:

  <Include
      xmlns="www.team-mediaportal.com/2008/mpf/directx"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Source="screens\master_menu.xaml">
    <Include.Resources>
      <ResourceWrapper x:Key="Header_Text">
        [Header text]
      </ResourceWrapper>
      <ControlTemplate x:Key="Contents_Template">
        [UI element to be displayed in the content area]
      </ControlTemplate>
    </Include.Resources>
  </Include>

Parameters which have to be accessible by a DynamicResource lookup:
 - Header_Text (String): The text to be displayed as header
 - Contents_Template (ConrolTemplate): Template for element to be displayed
   in the content area at the right side
-->

<Include
    xmlns="www.team-mediaportal.com/2008/mpf/directx"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Source="screens\master_bare.xaml"
    xmlns:mp_special_controls="clr-namespace:MediaPortal.UI.SkinEngine.SpecialElements.Controls"
    >
  <Include.Resources>
    <Model x:Key="MenuModel" Id="9E9D0CD9-4FDB-4c0f-A0C4-F356E151BDE0"/>
    
    <!-- Defines the default margins for the content area -->
    <ResourceWrapper x:Key="DefaultContentMargin" Resource="0,210,-4,-35" />
    
    <!-- Header has to be defined by the includer: "Header_Text" -->

    <!-- Client_Template -->
    <ControlTemplate x:Key="Client_Template">
      <Grid x:Name="MainPanel" Margin="10" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="780"/>
        </Grid.RowDefinitions>

        <!-- Order matters here: The content grid has to be the last control to fill the rest of the space -->
        <Border x:Name="ContentBackground" Background="#30000000" CornerRadius="0">
          <Grid x:Name="ContentPanel" SetFocusPrio="DefaultHigh">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="780"/>
            </Grid.RowDefinitions>
            <Control x:Name="ContentViewer" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                Template="{DynamicResource ResourceKey=Contents_Template}" SetFocus="true"/>
          </Grid>
          <Border.Margin>
            <MultiBinding Converter="{StaticResource PriorityBindingConverter}" AllowEmptyBinding="true">
              <Binding Source="{DynamicResource CustomContentMargin}"/>
              <Binding Source="{StaticResource DefaultContentMargin}"/>
            </MultiBinding>
          </Border.Margin>
        </Border>

        <Grid x:Name="LeftPanel" Margin="-550,-50,10,-75" VerticalAlignment="Stretch"
              Width="550" HorizontalAlignment="Left">

          <Grid.Resources>
            <Storyboard x:Key="SlideInStoryboard" FillBehavior="HoldEnd">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" FillBehavior="HoldEnd" Storyboard.TargetName="LeftPanel" Storyboard.TargetProperty="RenderTransform.X">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.20" Value="550"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
          </Grid.Resources>

          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="550"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>

          <Grid.RenderTransform>
            <TranslateTransform X="0"/>
          </Grid.RenderTransform>

          <Grid.Triggers>
            <!-- Setting default state of menu to hidden -->
            <EventTrigger RoutedEvent="Screen.Show">
              <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
            </EventTrigger>

            <!-- Slide-In animation when the MenuModel.ShowMenu gets true -->
            <DataTrigger Binding="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}" Value="True">
              <DataTrigger.EnterActions>
                <BeginStoryboard x:Name="SlideIn_BeginStoryboard" Storyboard="{ThemeResource SlideInStoryboard}"/>
              </DataTrigger.EnterActions>
              <DataTrigger.ExitActions>
                <StopStoryboard BeginStoryboardName="SlideIn_BeginStoryboard"/>
              </DataTrigger.ExitActions>

              <Setter TargetName="MainMenu" Property="SetFocusPrio" Value="Highest" />
              <Setter TargetName="MainMenu" Property="SetFocus" Value="True" />
            </DataTrigger>
          </Grid.Triggers>

          <Rectangle Fill="{ThemeResource DialogBackgroundBaseColor}" 
                     RadiusX="{ThemeResource DialogBorderCornerRadius}" RadiusY="{ThemeResource DialogBorderCornerRadius}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,52,0"/>
          <Rectangle RadiusX="{ThemeResource DialogBorderCornerRadius}" RadiusY="{ThemeResource DialogBorderCornerRadius}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,52,0">
            <Rectangle.Fill>
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="{ThemeResource DialogBackgroundGradient1Color}"/>
                <GradientStop Color="{ThemeResource DialogBackgroundGradient2Color}" Offset="0.874"/>
              </LinearGradientBrush>
            </Rectangle.Fill>
          </Rectangle>

          <ListView x:Name="MainMenu" Style="{ThemeResource MenuListViewStyle}" Margin="20,10,70,10"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SetFocusPrio="Default"
              ItemsSource="{Binding Source={StaticResource MenuModel},Path=MenuItems,Mode=OneTime}"
              IsEnabled="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}">
            <ListView.Resources>
              <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}"/>
            </ListView.Resources>
          </ListView>

          <Button x:Name="MenuShowButton" Content="Menu" Style="{ThemeResource ButtonWideStyle}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"
                   Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}">
            <Button.LayoutTransform>
              <RotateTransform Angle="270"/>
            </Button.LayoutTransform>
          </Button>

        </Grid>

        <KeyBinding Key="Info" Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}"/>
        <KeyBinding Key="Escape" Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}" IsEnabled="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}"/>
      </Grid>
    </ControlTemplate>

  </Include.Resources>
</Include>
