<ResourceDictionary xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
                    xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
                    x:CompileBindings="True">
    <Design.PreviewWith>
        <Border Padding="30" MinWidth="350">
            <TreeView ItemContainerTheme="{StaticResource MenuTreeViewItem}">
                <TreeViewItem>
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <avalonia:MaterialIcon Kind="Home" Width="16" Height="16" />
                            <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Home" />
                        </StackPanel>
                    </TreeViewItem.Header>
                </TreeViewItem>
                <TreeViewItem IsExpanded="True">
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <avalonia:MaterialIcon Kind="TestTube" Width="16" Height="16" />
                            <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Workshop" />
                        </StackPanel>
                    </TreeViewItem.Header>
                    <TreeViewItem>
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                                <avalonia:MaterialIcon Kind="FolderVideo" Width="16" Height="16" />
                                <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Profiles" />
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                    <TreeViewItem>
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                                <avalonia:MaterialIcon Kind="KeyboardVariant" Width="16" Height="16" />
                                <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Layouts" />
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                </TreeViewItem>
                <TreeViewItem>
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <avalonia:MaterialIcon Kind="Devices" Width="16" Height="16" />
                            <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Surface Editor" />
                        </StackPanel>
                    </TreeViewItem.Header>
                </TreeViewItem>
                <TreeViewItem>
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <avalonia:MaterialIcon Kind="Cog" Width="16" Height="16" />
                            <TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="Settings" />
                        </StackPanel>
                    </TreeViewItem.Header>
                </TreeViewItem>
            </TreeView>
        </Border>
    </Design.PreviewWith>

    <x:Double x:Key="TreeViewItemIndent">31</x:Double>
    <x:Double x:Key="TreeViewItemExpandCollapseChevronSize">12</x:Double>
    <Thickness x:Key="TreeViewItemExpandCollapseChevronMargin">12, 0, 12, 0</Thickness>
    <converters:MarginMultiplierConverter Indent="{StaticResource TreeViewItemIndent}"
                                          Left="True"
                                          x:Key="TreeViewItemLeftMarginConverter" />

    <ControlTheme TargetType="TreeViewItem" x:Key="MenuTreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
        <Setter Property="Template">
            <ControlTemplate>
                <StackPanel>
                    <Border Name="PART_LayoutRoot"
                            Classes="TreeViewItemLayoutRoot"
                            Focusable="True"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            MinHeight="{DynamicResource NavigationViewItemOnLeftMinHeight}"
                            CornerRadius="{DynamicResource ControlCornerRadius}"
                            TemplatedControl.IsTemplateFocusTarget="True"
                            Margin="2">
                        <Panel>
                            <Grid Name="PART_Header"
                                  ColumnDefinitions="12, *, Auto"
                                  Margin="{TemplateBinding Level, Mode=OneWay, Converter={StaticResource TreeViewItemLeftMarginConverter}}">
                                <Rectangle Name="SelectionIndicator"
                                           Width="3"
                                           Height="16"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           RadiusX="2"
                                           RadiusY="2"
                                           IsVisible="False"
                                           Fill="{DynamicResource TreeViewItemSelectionIndicatorForeground}" />

                                <ContentPresenter Name="PART_HeaderPresenter"
                                                  Grid.Column="1"
                                                  Focusable="False"
                                                  Content="{TemplateBinding Header}"
                                                  ContentTemplate="{TemplateBinding HeaderTemplate}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                                  Margin="{TemplateBinding Padding}" />
                                <Panel Name="PART_ExpandCollapseChevronContainer" Grid.Column="2">
                                    <ToggleButton Name="PART_ExpandCollapseChevron"
                                                  Theme="{StaticResource TreeViewChevronButton}"
                                                  Focusable="False"
                                                  Margin="{StaticResource TreeViewItemExpandCollapseChevronMargin}"
                                                  IsChecked="{TemplateBinding IsExpanded, Mode=TwoWay}" />
                                </Panel>
                            </Grid>
                        </Panel>
                    </Border>
                    <ItemsPresenter Name="PART_ItemsPresenter"
                                    IsVisible="{TemplateBinding IsExpanded}"
                                    ItemsPanel="{TemplateBinding ItemsPanel}" />
                </StackPanel>
            </ControlTemplate>
        </Setter>
    </ControlTheme>
</ResourceDictionary>