<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:l="clr-namespace:Xwt.WPFBackend;assembly=Xwt.WPF">

	<Style TargetType="{x:Type l:ExTreeViewItem}">
		<Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="l:ExTreeViewItem">
					<StackPanel>
						<Border Name="HBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
							<GridViewRowPresenter x:Name="PART_Header" Content="{TemplateBinding Header}" Columns="{Binding Path=View.Columns, RelativeSource={RelativeSource AncestorType={x:Type l:ExTreeView}}}" />
						</Border>
						<ItemsPresenter x:Name="ItemsHost" />
					</StackPanel>

					<ControlTemplate.Triggers>
						<Trigger Property="IsExpanded" Value="False">
							<Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
						</Trigger>

						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="HasHeader" Value="False" />
								<Condition Property="Width" Value="Auto" />
							</MultiTrigger.Conditions>
							<Setter TargetName="PART_Header" Property="MinWidth" Value="75" />
						</MultiTrigger>

						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="HasHeader" Value="False" />
								<Condition Property="Height" Value="Auto" />
							</MultiTrigger.Conditions>
							<Setter Property="MinHeight" Value="19" />
						</MultiTrigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>

		<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
		<Setter Property="BorderThickness" Value="1" />
		<Style.Triggers>
			<Trigger Property="IsSelected" Value="True">
				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
				<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
			</Trigger>

			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="IsSelected" Value="True" />
					<Condition Property="IsSelectionActive" Value="False" />
				</MultiTrigger.Conditions>
				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
				<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
				<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
			</MultiTrigger>

			<Trigger Property="IsEnabled" Value="False">
				<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
			</Trigger>
			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="IsSelected" Value="False" />
					<Condition Property="IsFocused" Value="False" />
				</MultiTrigger.Conditions>
				<Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Background}" />
			</MultiTrigger>
		</Style.Triggers>
	</Style>
	
	<Style TargetType="{x:Type l:ExTreeView}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate>
					<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
						<ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}" Padding="{TemplateBinding Padding}">
							<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
						</ScrollViewer>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>