<!--***********************************************************************************

   Extended WPF Toolkit

   Copyright (C) 2007-2013 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at http://xceed.com/wpf_toolkit

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  **********************************************************************************-->

<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:conv="clr-namespace:Xceed.Wpf.Toolkit.Converters"
                    xmlns:local="clr-namespace:Xceed.Wpf.Toolkit">

   <!-- =============================================================================== -->
   <!-- BusyIndicator                                                                   -->
   <!-- =============================================================================== -->
   <conv:ProgressBarWidthConverter x:Key="ProgressBarWidthConverter" />

   <Style TargetType="{x:Type local:BusyIndicator}">
      <Setter Property="BusyContent" Value="Please wait..." />
      <Setter Property="IsTabStop" Value="False" />
      <Setter Property="Focusable" Value="False" />
      <Setter Property="OverlayStyle">
         <Setter.Value>
            <Style TargetType="Rectangle">
               <Setter Property="Fill" Value="White" />
               <Setter Property="Opacity" Value="0.5" />
            </Style>
         </Setter.Value>
      </Setter>
      <Setter Property="ProgressBarStyle">
         <Setter.Value>
            <Style TargetType="ProgressBar">
               <Setter Property="IsIndeterminate" Value="True" />
               <Setter Property="Height" Value="15" />
               <Setter Property="Margin" Value="8,0,8,8" />
            </Style>
         </Setter.Value>
      </Setter>
      <Setter Property="DisplayAfter" Value="00:00:00.1" />
      <Setter Property="HorizontalAlignment" Value="Stretch" />
      <Setter Property="VerticalAlignment" Value="Stretch" />
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
      <Setter Property="VerticalContentAlignment" Value="Stretch" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:BusyIndicator}">
               <Grid>
                  <VisualStateManager.VisualStateGroups>
                     <VisualStateGroup x:Name="VisibilityStates">
                        <VisualState x:Name="Hidden">
                           <Storyboard>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="busycontent" Storyboard.TargetProperty="(UIElement.Visibility)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="overlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                           </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Visible">
                           <Storyboard>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="busycontent" Storyboard.TargetProperty="(UIElement.Visibility)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="overlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                           </Storyboard>
                        </VisualState>
                     </VisualStateGroup>
                     <VisualStateGroup x:Name="BusyStatusStates">
                        <VisualState x:Name="Idle">
                           <Storyboard>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="content" Storyboard.TargetProperty="(Control.IsEnabled)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <sys:Boolean>True</sys:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                           </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Busy">
                           <Storyboard>
                              <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetName="content" Storyboard.TargetProperty="(Control.IsEnabled)">
                                 <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                       <sys:Boolean>False</sys:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                 </DiscreteObjectKeyFrame>
                              </ObjectAnimationUsingKeyFrames>
                           </Storyboard>
                        </VisualState>
                     </VisualStateGroup>
                  </VisualStateManager.VisualStateGroups>
                  <ContentControl x:Name="content" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsTabStop="False" Focusable="False" />
                  <Rectangle x:Name="overlay" Style="{TemplateBinding OverlayStyle}" />
                  <ContentPresenter x:Name="busycontent">
                     <ContentPresenter.Content>
                        <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                           <Border Background="White" BorderThickness="1" CornerRadius="2">
                              <Border.BorderBrush>
                                 <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                    <GradientStop Color="#FFA3AEB9" Offset="0" />
                                    <GradientStop Color="#FF8399A9" Offset="0.375" />
                                    <GradientStop Color="#FF718597" Offset="0.375" />
                                    <GradientStop Color="#FF617584" Offset="1" />
                                 </LinearGradientBrush>
                              </Border.BorderBrush>
                              <Border CornerRadius="1.5" Margin="1">
                                 <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                       <GradientStop Color="#FFF6F8F9" Offset="0.02" />
                                       <GradientStop Color="#FFB8B8B8" Offset="0.996" />
                                    </LinearGradientBrush>
                                 </Border.Background>
                                 <Grid x:Name="_grid" 
                                       MinWidth="150">
                                    <Grid.RowDefinitions>
                                       <RowDefinition />
                                       <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <ContentPresenter x:Name="busyContent"
                                                      Content="{TemplateBinding BusyContent}"
                                                      ContentTemplate="{TemplateBinding BusyContentTemplate}"
                                                      HorizontalAlignment="Center"
                                                      Margin="8" />
                                    <ProgressBar Grid.Row="1" Style="{TemplateBinding ProgressBarStyle}" >
                                       <ProgressBar.Width>
                                          <MultiBinding Converter="{StaticResource ProgressBarWidthConverter}">
                                             <Binding Path="ActualWidth"
                                                      ElementName="busyContent" />
                                             <Binding Path="MinWidth"
                                                      ElementName="_grid" />
                                          </MultiBinding>
                                       </ProgressBar.Width>
                                    </ProgressBar>
                                 </Grid>
                              </Border>
                           </Border>
                        </Grid>
                     </ContentPresenter.Content>
                  </ContentPresenter>
               </Grid>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

</ResourceDictionary>
