<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:converter="clr-namespace:Reloaded.WPF.Theme.Default.Converter;assembly=Reloaded.WPF.Theme.Default"
                    xmlns:controls="clr-namespace:Reloaded.WPF.Controls;assembly=Reloaded.WPF">

    <!-- For IntelliSense: Uncomment only when editing. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <controls:SharedResourceDictionary Source="pack://siteoforigin:,,,/Theme/Default/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    
    <!-- The code below expects the Window's DataContext to be set to WindowViewModel -->
    <!-- Style the Window. -->
    <Style x:Key="ReloadedWindow" TargetType="{x:Type Window}">
        
        <!-- Redefine Window Template -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">

                    <AdornerDecorator>
                        <!-- Gives us invisible padding space to allow for rendering of drop shadow. -->
                        <Border Padding="{Binding Path=DropShadowBorderSize}" Background="Transparent">
                            <Grid>
                                <!-- The glowing border of the Window.
                                 The important thing is that this must be separate and not nest the content below!
                                 The DropShadowEffect uses all descendant objects to calculate the shape of the shadow. 
                                 which means that every time any children are updated the shadow is recalculated. -->
                                <Border x:Name="DropShadowBorder"
                                    CornerRadius="{DynamicResource CornerRadius}"
                                    Background="{Binding Path=Background, 
                                                         RelativeSource={RelativeSource AncestorType={x:Type Window}}, 
                                                         FallbackValue=#181818}">
                                    <Border.Effect>
                                        <DropShadowEffect
                                        ShadowDepth="{DynamicResource GlowDepth}"
                                        Direction="{DynamicResource GlowDirection}"
                                        RenderingBias="{DynamicResource GlowRenderBias}"
                                        Color="{Binding Path=GlowColor,
                                                        Converter={x:Static converter:ColorToShadowColorConverter.Instance}}"
                                        BlurRadius="{Binding Path=DropShadowSize}"
                                        Opacity="{DynamicResource GlowOpacity}" />
                                    </Border.Effect>
                                </Border>

                                <!-- This is our window background and the owner of what we see onscreen. -->
                                <Border x:Name="ContentBorder" 
                                    Background="Transparent"
                                    CornerRadius="{DynamicResource CornerRadius}">
                                    <Border.Clip>
                                        <MultiBinding Converter="{x:Static converter:BorderClipConverter.Instance}">
                                            <Binding Path="ActualWidth"  RelativeSource="{RelativeSource Self}"/>
                                            <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
                                            <Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}"/>
                                        </MultiBinding>
                                    </Border.Clip>

                                    <!-- Main Window Content -->
                                    <Grid>

                                        <!-- TitleBar and rest of page for content. -->
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="{DynamicResource TitleBarHeight}"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>

                                        <!-- Title Bar -->
                                        <Grid Background="{DynamicResource AccentColorLightBrush}" 
                                              Grid.Row="0">

                                            <!-- Title & Buttons -->
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"></ColumnDefinition>
                                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                            </Grid.ColumnDefinitions>

                                            <Viewbox Grid.Column="0" Grid.ColumnSpan="2" Style="{DynamicResource HeaderAlignment}">
                                                <TextBlock
                                                    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue='Window Title'}"
                                                    Style="{DynamicResource HeaderText}"
                                                >
                                                </TextBlock>
                                            </Viewbox>

                                            <StackPanel Grid.Column="1" Orientation="Horizontal">
                                                <Button Command="{Binding Path=MinimizeCommand}" 
                                                        Visibility="{Binding Path=MinimizeButtonVisibility}"
                                                        Content="—" 
                                                        Style="{DynamicResource WindowControlButton}"/>
                                                <Button Command="{Binding Path=MaximizeCommand}" 
                                                        Visibility="{Binding Path=MaximizeButtonVisibility}"
                                                        Content="O" 
                                                        Style="{DynamicResource WindowControlButton}"/>
                                                <Button Command="{Binding Path=CloseCommand}"
                                                        Visibility="{Binding Path=CloseButtonVisibility}"
                                                        Content="X"
                                                        Style="{DynamicResource WindowControlButton}"/>
                                            </StackPanel>
                                        </Grid>

                                        <!-- Window Content Goes in Here -->
                                        <Grid Grid.Row="1">
                                            <ContentPresenter Content="{TemplateBinding Content}"/>
                                        </Grid>
                                    </Grid>
                                </Border>
                            </Grid>
                        </Border>
                    </AdornerDecorator>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!-- WindowChrome for Window Dragging, Round Corners -->
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome CaptionHeight="{Binding Path=WindowChromeTitleBarHeight,
                                              FallbackValue=44}"
                              CornerRadius="{DynamicResource CornerRadius}"
                              ResizeBorderThickness="{Binding Path=ResizeBorderThickness}"
                />
            </Setter.Value>
        </Setter>

        <!-- Window Properties -->
        <Setter Property="Background" Value="{DynamicResource BackgroundColorBrush}"/>
        <Setter Property="AllowsTransparency" Value="True"/>
        <Setter Property="WindowStyle" Value="None"/>
    </Style>

</ResourceDictionary>