<!--================================================================================================
## CommonHelpers satellite library | Author: Sergei Y.Kitáev
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-->
<ResourceDictionary
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
   xmlns:userwin="clr-namespace:UserWin">

   <sys:Double x:Key="BusyOverlayOpacity">0.2</sys:Double>
   <KeyTime x:Key="BusyOverlayAppearanceInterval">00:00:02.0</KeyTime>
   <KeyTime x:Key="BusyOverlayAppearanceDelay">00:00:00.5</KeyTime>

   <LinearGradientBrush x:Key="BusyOverlayBrush">
      <GradientStop Color="#00000000" Offset="0" />
      <GradientStop Color="PowderBlue" Offset="0.5" />
      <GradientStop Color="#00000000" Offset="1" />
   </LinearGradientBrush>

   <Style x:Key="BusyOverlayRectangleAppearanceStyle" TargetType="{x:Type Rectangle}">
      <Setter Property="Fill" Value="{StaticResource BusyOverlayBrush}" />
      <Style.Triggers>
         <Trigger Property="Visibility" Value="Visible">
            <Trigger.EnterActions>
               <BeginStoryboard>
                  <Storyboard>
                     <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetProperty="Opacity">
                        <LinearDoubleKeyFrame
                           Value="0.0"
                           KeyTime="00:00:00.0" />
                        <LinearDoubleKeyFrame
                           Value="0.0"
                           KeyTime="{StaticResource BusyOverlayAppearanceDelay}" />
                        <LinearDoubleKeyFrame
                           Value="{StaticResource BusyOverlayOpacity}"
                           KeyTime="{StaticResource BusyOverlayAppearanceInterval}" />
                     </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
               </BeginStoryboard>
            </Trigger.EnterActions>
         </Trigger>
      </Style.Triggers>
   </Style>

   <Storyboard x:Key="BusyOverlayMovableRectangleStoryboard">
      <DoubleAnimationUsingKeyFrames
            Storyboard.TargetProperty="Fill.GradientStops[1].Offset"
            RepeatBehavior="Forever">
         <LinearDoubleKeyFrame Value="0.5" KeyTime="0:0:0" />
         <LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:2" />
         <LinearDoubleKeyFrame Value="0.0" KeyTime="0:0:6" />
         <LinearDoubleKeyFrame Value="0.5" KeyTime="0:0:8" />
      </DoubleAnimationUsingKeyFrames>
   </Storyboard>

   <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type userwin:UXWinResources},
                        ResourceId=BusyOverlayDataTemplate}">
      <Rectangle Style="{StaticResource BusyOverlayRectangleAppearanceStyle}"
                 HorizontalAlignment="{x:Static userwin:UXBusyOverlayHelpers.HorizontalAlignment}">
         <Rectangle.Visibility>
            <Binding Path="IsBusy"
                     RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}">
               <Binding.Converter>
                  <userwin:UXBusyToOverlayVisibilityConverter />
               </Binding.Converter>
            </Binding>
         </Rectangle.Visibility>
      </Rectangle>
   </DataTemplate>

   <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type userwin:UXWinResources},
                        ResourceId=BusyOverlayInstantDataTemplate}">
      <Rectangle Fill="{StaticResource BusyOverlayBrush}"
                 HorizontalAlignment="{x:Static userwin:UXBusyOverlayHelpers.HorizontalAlignment}">
         <Rectangle.Visibility>
            <Binding Path="IsBusy"
                     RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}">
               <Binding.Converter>
                  <userwin:UXBusyToOverlayVisibilityConverter />
               </Binding.Converter>
            </Binding>
         </Rectangle.Visibility>
      </Rectangle>
   </DataTemplate>

   <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type userwin:UXWinResources},
                        ResourceId=BusyOverlayMovableDataTemplate}">
      <Rectangle Style="{StaticResource BusyOverlayRectangleAppearanceStyle}"
                 HorizontalAlignment="{x:Static userwin:UXBusyOverlayHelpers.HorizontalAlignment}">
         <Rectangle.Visibility>
            <Binding Path="IsBusy"
                     RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}">
               <Binding.Converter>
                  <userwin:UXBusyToOverlayVisibilityConverter />
               </Binding.Converter>
            </Binding>
         </Rectangle.Visibility>
         <Rectangle.Triggers>
            <EventTrigger RoutedEvent="FrameworkContentElement.Loaded">
               <EventTrigger.Actions>
                  <BeginStoryboard
                     Storyboard="{StaticResource BusyOverlayMovableRectangleStoryboard}" />
               </EventTrigger.Actions>
            </EventTrigger>
         </Rectangle.Triggers>
      </Rectangle>
   </DataTemplate>

   <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type userwin:UXWinResources},
                        ResourceId=BusyOverlayInstantMovableDataTemplate}">
      <Rectangle Fill="{StaticResource BusyOverlayBrush}"
                 HorizontalAlignment="{x:Static userwin:UXBusyOverlayHelpers.HorizontalAlignment}">
         <Rectangle.Visibility>
            <Binding Path="IsBusy"
                     RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type Window}}">
               <Binding.Converter>
                  <userwin:UXBusyToOverlayVisibilityConverter />
               </Binding.Converter>
            </Binding>
         </Rectangle.Visibility>
         <Rectangle.Triggers>
            <EventTrigger RoutedEvent="FrameworkContentElement.Loaded">
               <EventTrigger.Actions>
                  <BeginStoryboard
                     Storyboard="{StaticResource BusyOverlayMovableRectangleStoryboard}" />
               </EventTrigger.Actions>
            </EventTrigger>
         </Rectangle.Triggers>
      </Rectangle>
   </DataTemplate>

</ResourceDictionary>
