<UserControl x:Class="Txgy.EWS.Client.MainModule.Views.TreeMenuView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Txgy.EWS.Client.MainModule.Views"
             xmlns:prism="http://prismlibrary.com/"
             xmlns:hc="https://handyorg.github.io/handycontrol"
             prism:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="450"
             d:DesignWidth="800"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Txgy.EWS.Client.Assets;component/Styles/BaseResources.xaml" />
                <ResourceDictionary>
                    <ControlTemplate x:Key="ArrowButtonTemplate" TargetType="ToggleButton">
                        <Grid Name="back" Background="Transparent">
                            <TextBlock Name="arrow"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       Text="&#xe81d;"
                                       FontFamily="{StaticResource Iconfont}"
                                       RenderTransformOrigin="0.5,0.5">
                            </TextBlock>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="arrow" Property="RenderTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="90" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="back" Property="Background" Value="#11000000" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.Resources>
            <Style TargetType="TreeViewItem">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}">
                </Setter>
                <!--<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />-->
                <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
                <Setter Property="HorizontalContentAlignment" Value="Left" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="Padding" Value="8,5" />
                <Setter Property="Foreground" Value="White" />
                <!--<Setter Property="FontFamily" Value="{StaticResource Iconfont}"/>-->
                <Setter Property="FontSize" Value="12" />
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TreeViewItem">
                            <Grid Name="root" Background="Transparent">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition MaxWidth="30" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" MinHeight="36" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.InputBindings>
                                    <MouseBinding MouseAction="LeftDoubleClick"
                                                  Command="{Binding OpenViewCommand}"
                                                  CommandParameter="{Binding}" />
                                </Grid.InputBindings>

                                <Border x:Name="Bd"
                                        Grid.ColumnSpan="2"
                                        Padding="{TemplateBinding Padding}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        Background="{TemplateBinding Background}"
                                        CornerRadius="0"
                                        SnapsToDevicePixels="true">
                                    <ContentPresenter x:Name="PART_Header"
                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                      ContentSource="Header"
                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                                    </ContentPresenter>
                                </Border>
                                <ToggleButton x:Name="Expander"
                                              Grid.Column="1"
                                              ClickMode="Press"
                                              IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                                              Template="{StaticResource ArrowButtonTemplate}" />
                                <ItemsPresenter x:Name="ItemsHost"
                                                Grid.Row="1"
                                                Grid.ColumnSpan="2"
                                                Margin="18,0,0,0" />
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="false">
                                    <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
                                </Trigger>
                                <Trigger Property="HasItems" Value="false">
                                    <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                                </Trigger>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter TargetName="Bd" Property="Background" Value="#FF0ABEFF" />
                                    <Setter Property="Foreground" Value="#FFFFFFFF" />
                                    <Setter TargetName="Expander" Property="Foreground" Value="#FFFFFFFF" />
                                </Trigger>
                                <!-- 被选中后失去焦点 -->
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsSelected" Value="true" />
                                        <Condition Property="IsSelectionActive" Value="false" />
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="Bd" Property="Background" Value="#FF0ABEFF" />
                                    <Setter Property="Foreground" Value="#FFFFFFFF" />
                                </MultiTrigger>
                                <DataTrigger Binding="{Binding MenuIcon}" Value="{x:Null}">
                                    <Setter TargetName="root" Property="Margin" Value="10,0,0,0" />
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <!--#region 20230305-->
        <TreeView Margin="0,10"
                  BorderThickness="0"
                  Background="Transparent"
                  ItemsSource="{Binding Menus}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <Grid Margin="30,15,0,15" VerticalAlignment="Center">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Name="c1" Width="30" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="{Binding MenuIcon}"
                                   FontSize="20"
                                   SnapsToDevicePixels="True"
                                   FontFamily="{StaticResource Iconfont}" />
                        <TextBlock Grid.Column="1"
                                   Margin="5,0,0,0"
                                   Text="{Binding MenuHeader}"
                                   FontSize="20" />
                    </Grid>
                    <HierarchicalDataTemplate.Triggers>
                        <DataTrigger Binding="{Binding MenuIcon}" Value="{x:Null}">
                            <Setter TargetName="c1" Property="Width" Value="0" />
                        </DataTrigger>
                    </HierarchicalDataTemplate.Triggers>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
        <!--#endregion-->
    </Grid>
</UserControl>
