<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ChartSamples" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">

    <!-- Default Settings -->
    <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
    <Style x:Key="DisabledStyle" TargetType="Rectangle">
        <Setter Property="RadiusX" Value="1" />
        <Setter Property="RadiusY" Value="1" />
        <Setter Property="Opacity" Value="0" />
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="StrokeThickness" Value="0" />
        <Setter Property="Stroke" Value="{StaticResource DisabledBrush}" />
        <Setter Property="Fill" Value="{StaticResource DisabledBrush}" />
    </Style>

    <ControlTemplate TargetType="ToggleButton" x:Key="C1TreeViewToggle">
        <Grid Cursor="Arrow">
            <Grid.Resources>
                <!-- Visual constants used by the template -->
                <SolidColorBrush x:Key="Background" Color="#FF003255" />
                <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
                <LinearGradientBrush x:Key="BoxStrokeBrush" StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#FF000000" Offset="0" />
                    <GradientStop Color="#FF000000" Offset="1" />
                    <GradientStop Color="#FF000000" Offset="0.325" />
                    <GradientStop Color="#FF000000" Offset="0.325" />
                </LinearGradientBrush>
                <LinearGradientBrush x:Key="FocusedStrokeBrush" StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#B2FFFFFF" Offset="0" />
                    <GradientStop Color="#51FFFFFF" Offset="1" />
                    <GradientStop Color="#66FFFFFF" Offset="0.325" />
                    <GradientStop Color="#1EFFFFFF" Offset="0.325" />
                </LinearGradientBrush>
                <LinearGradientBrush x:Key="ExpandFillBrush" StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#FFf9fafa" Offset="0" />
                    <GradientStop Color="#FFb8c5cf" Offset="1" />
                    <GradientStop Color="#FFf4f6f7" Offset="0.325" />
                    <GradientStop Color="#FFdee4e8" Offset="0.325" />
                </LinearGradientBrush>
                <Color x:Key="ExpandFillColor">#00000000</Color>
                <Color x:Key="BorderColor">#FF000000</Color>
                <Color x:Key="IconColor">#FF595959</Color>
                <Color x:Key="PressedIconColor">#FF000000</Color>
                <Color x:Key="MiddleBoxStrokeBrush">#FFADADAD</Color>
                <Color x:Key="MiddleBoxStrokeBrushOver">#FF656565</Color>
                <Color x:Key="LinearBevelLightStartColor">#FFFFFFFF</Color>
                <Color x:Key="LinearBevelLightEndColor">#FFFFFFFF</Color>
                <Color x:Key="LinearBevelDarkStartColor">#FFFFFFFF</Color>
                <Color x:Key="LinearBevelDarkEndColor">#FFFFFFFF</Color>
                <Color x:Key="LinearBevelLightStartColor2">#FCFFFFFF</Color>
                <Color x:Key="LinearBevelLightEndColor2">#F4FFFFFF</Color>
                <Color x:Key="LinearBevelDarkStartColor2">#E0FFFFFF</Color>
                <Color x:Key="LinearBevelDarkEndColor2">#19FFFFFF</Color>
                <Color x:Key="LinearBevelLightEndColor3">#FCFFFFFF</Color>
                <Color x:Key="LinearBevelDarkStartColor3">#FCFFFFFF</Color>
                <Color x:Key="LinearBevelDarkEndColor3">#FCFFFFFF</Color>
                <Color x:Key="LinearBevelIndeterminateStartColor2">#BFFFFFFF</Color>
                <Color x:Key="LinearBevelIndeterminateEndColor2">#E0FFFFFF</Color>
                <Color x:Key="FocusColor">#FF333333</Color>
            </Grid.Resources>
            <vsm:VisualStateManager.VisualStateGroups>
                <vsm:VisualStateGroup x:Name="CommonStates">
                    <vsm:VisualStateGroup.Transitions>
                        <vsm:VisualTransition To="MouseOver" GeneratedDuration="0:0:0.1" />
                        <vsm:VisualTransition To="Pressed" GeneratedDuration="0:0:0.1" />
                    </vsm:VisualStateGroup.Transitions>
                    <vsm:VisualState x:Name="Normal" />
                    <vsm:VisualState x:Name="MouseOver" />
                    <vsm:VisualState x:Name="Pressed" />
                    <vsm:VisualState x:Name="Disabled" />
                </vsm:VisualStateGroup>
                <vsm:VisualStateGroup x:Name="CheckStates">
                    <vsm:VisualStateGroup.Transitions>
                        <vsm:VisualTransition To="Indeterminate" GeneratedDuration="0:0:0.1" />
                    </vsm:VisualStateGroup.Transitions>
                    <vsm:VisualState x:Name="Checked">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="CollapseIcon" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                            <DoubleAnimation Storyboard.TargetName="ExpandIcon" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                        </Storyboard>
                    </vsm:VisualState>
                    <vsm:VisualState x:Name="Unchecked">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="CollapseIcon" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                            <DoubleAnimation Storyboard.TargetName="ExpandIcon" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                        </Storyboard>
                    </vsm:VisualState>
                    <vsm:VisualState x:Name="Indeterminate" />
                </vsm:VisualStateGroup>
                <vsm:VisualStateGroup x:Name="FocusStates">
                    <vsm:VisualState x:Name="Unfocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </vsm:VisualState>
                    <vsm:VisualState x:Name="Focused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </vsm:VisualState>
                    <vsm:VisualState x:Name="ContentFocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </vsm:VisualState>
                </vsm:VisualStateGroup>
            </vsm:VisualStateManager.VisualStateGroups>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Rectangle x:Name="BoxMiddleBackground" Width="9" Height="9" RadiusX="1" RadiusY="1" StrokeThickness=".5" Fill="{TemplateBinding Background}" VerticalAlignment="Center" Opacity=".20" />
            <Rectangle x:Name="BoxMiddle" Width="9" Height="9" RadiusX=".75" RadiusY=".75" StrokeThickness=".5" VerticalAlignment="Center">
                <Rectangle.Stroke>
                    <SolidColorBrush x:Name="BoxMiddleStroke" Color="{StaticResource MiddleBoxStrokeBrush}" />
                </Rectangle.Stroke>
                <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0.7,0" EndPoint="0.7,1">
                        <GradientStop x:Name="LinearBevelLightStart2" Color="{StaticResource LinearBevelLightStartColor2}" Offset="0" />
                        <GradientStop x:Name="LinearBevelLightEnd2" Color="{StaticResource LinearBevelLightEndColor2}" Offset="0.35" />
                        <GradientStop x:Name="LinearBevelDarkStart2" Color="{StaticResource LinearBevelDarkStartColor2}" Offset="0.35" />
                        <GradientStop x:Name="LinearBevelDarkEnd2" Color="{StaticResource LinearBevelDarkEndColor2}" Offset="1" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            
            <Path x:Name="ExpandIcon" Width="5" Height="5" HorizontalAlignment="Center" VerticalAlignment="Center" StrokeThickness="0" Margin="0,0,0,0" Stretch="Fill" Opacity="0" Data="M1.75,0 L2.25,0 C2.3880711,0 2.5,0.11192881 2.5,0.25 L2.5,1.5 L3.75,1.5 C3.8880713,1.5 4,1.6119288 4,1.75 L4,2.25 C4,2.3880713 3.8880713,2.5 3.75,2.5 L2.5,2.5 L2.5,3.75 C2.5,3.8880713 2.3880711,4 2.25,4 L1.75,4 C1.6119288,4 1.5,3.8880713 1.5,3.75 L1.5,2.5 L0.25,2.5 C0.11192882,2.5 0,2.3880713 0,2.25 L0,1.75 C0,1.6119288 0.11192882,1.5 0.25,1.5 L1.5,1.5 L1.5,0.25 C1.5,0.11192881 1.6119288,0 1.75,0 z">
                <Path.Fill>
                    <SolidColorBrush x:Name="ExpandIconColor" Color="{StaticResource IconColor}" />
                </Path.Fill>
            </Path>

            <Path x:Name="CollapseIcon" Width="5" Height="1.5" HorizontalAlignment="Center" VerticalAlignment="Center" StrokeThickness="0" Margin="0,0,0,0" Stretch="Fill" Opacity="0" Data="M0,0.25 C0,0.11192881 0.11192881,0 0.25,0 L0.75,0 C0.88807118,0 1,0.11192881 1,0.25 L1,3.75 C1,3.8880713 0.88807118,4 0.75,4 L0.25,4 C0.11192881,4 0,3.8880713 0,3.75 z">
                <Path.Fill>
                    <SolidColorBrush x:Name="IconColor" Color="{StaticResource IconColor}" />
                </Path.Fill>
            </Path>

            <Rectangle Grid.Column="1" x:Name="ContentFocusVisual" StrokeDashCap="Round" Margin="2" StrokeDashArray=".2 2" Visibility="Collapsed" IsHitTestVisible="false">
                <Rectangle.Stroke>
                    <SolidColorBrush Color="{StaticResource FocusColor}" />
                </Rectangle.Stroke>
            </Rectangle>
            <ContentPresenter x:Name="Content" Grid.Column="1" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="6,5.5,4,4" IsHitTestVisible="false" />
            <Rectangle x:Name="DisabledBox" Width="13" Height="13" RadiusX="1" RadiusY="1" StrokeThickness=".75" Stroke="{StaticResource DisabledBrush}" Fill="{StaticResource DisabledBrush}" VerticalAlignment="Center" Opacity="0" />

        </Grid>
    </ControlTemplate>
    
    <Style TargetType="local:ControlNode">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ControlNode">
                    <Grid>
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="DisabledVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.0" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="fillStop3" Storyboard.TargetProperty="Color" Duration="0" To="#FF27303B" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="SelectedStates">
                                <vsm:VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="fillStop0" Storyboard.TargetProperty="Color" Duration="0" To="#FF364455" />

                                        <ColorAnimation Storyboard.TargetName="strokeStop0" Storyboard.TargetProperty="Color" Duration="0" To="#FF26374B" />
                                        <ColorAnimation Storyboard.TargetName="strokeStop1" Storyboard.TargetProperty="Color" Duration="0" To="#FF26374B" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Unselected" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid x:Name="HeaderPanel" Height="20" Grid.Row="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="15" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <ToggleButton x:Name="ExpandButton" Cursor="Hand" Width="13" Height="13" Margin="0,0,2,0" VerticalAlignment="Center" IsThreeState="False" Grid.Column="0" Template="{StaticResource C1TreeViewToggle}" />
                            <Rectangle IsHitTestVisible="False" Grid.Column="1" RadiusX="2" RadiusY="2">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0.316111,0.0165521" EndPoint="0.316111,0.724833">
                                        <GradientStop x:Name="fillStop0" Color="#00000000" Offset="0" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Rectangle IsHitTestVisible="False" Grid.Column="1" RadiusX="2" RadiusY="2">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0.316111,0.0165521" EndPoint="0.316111,0.724833">
                                        <GradientStop x:Name="fillStop3" Color="#00000000" Offset="0" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                                <Rectangle.Stroke>
                                    <LinearGradientBrush StartPoint="0.318122,0.0360108" EndPoint="0.318122,0.715784">
                                        <GradientStop x:Name="strokeStop0" Color="#00000000" Offset="0" />
                                        <GradientStop x:Name="strokeStop1" Color="#00000000" Offset="1" />
                                    </LinearGradientBrush>
                                </Rectangle.Stroke>
                            </Rectangle>
                            <ContentControl x:Name="Header" Content="{TemplateBinding Header}" Margin="5 0 5 0 " VerticalAlignment="Center" Grid.Column="1" Background="{TemplateBinding Background}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
                            </ContentControl>
                        </Grid>
                        <Border Padding="15 0 0 0" Grid.Row="1">
                            <ItemsPresenter x:Name="ChildrenPanel" Margin="-1,0,0,0" />
                        </Border>
                        <Rectangle x:Name="DisabledVisual" Style="{StaticResource DisabledStyle}" Grid.RowSpan="2" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>