<UserControl x:Class="Txgy.EWS.Client.SysModule.Views.MenuManagementView"
             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.SysModule.Views"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/BaseResources.xaml"/>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/ButtonStyles.xaml"/>
                <ResourceDictionary Source="/Txgy.EWS.Client.Assets;component/Styles/TextBoxStyle.xaml"/>
                <ResourceDictionary>
                    <ControlTemplate TargetType="ToggleButton" x:Key="ExpandeButtonTemplate">
                        <Border Background="#FF0ABEFF" CornerRadius="3" Width="15" Height="15">
                            <Path Data="M0 4 8 4M4 0 4 8" Stroke="White" StrokeThickness="1" Name="path"
                                  VerticalAlignment="Center" HorizontalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Data" Value="M0 0 8 0" TargetName="path"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                    <ControlTemplate TargetType="RadioButton" x:Key="ListRowTemplate">
                        <Grid Background="Transparent" Name="back">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="30"/>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition SharedSizeGroup="column1"/>
                                <ColumnDefinition SharedSizeGroup="column2"/>
                                <ColumnDefinition SharedSizeGroup="column3"/>
                            </Grid.ColumnDefinitions>
                            <ToggleButton IsChecked="{Binding IsExpanded}" Name="expandBox" Width="15" Height="15" Visibility="Collapsed"
                                          Template="{StaticResource ExpandeButtonTemplate}"/>
                            <TextBlock Text="{Binding MenuHeader}" VerticalAlignment="Center" Grid.Column="1"/>
                            <TextBlock Text="{Binding TargetView}" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="2" />
                            <TextBlock Text="{Binding MenuIcon}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="3" 
                                       FontFamily="{StaticResource Iconfont}"/>
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="4" Name="operationPanel">
                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="4" Margin="0,0,3,0">
                                        <Hyperlink Command="{Binding EditCommand}"
                                                   CommandParameter="{Binding}">编辑</Hyperlink>
                                </TextBlock>
                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="4" Margin="3,0,0,0">
                                        <Hyperlink Command="{Binding DeleteCommand}"
                                                   CommandParameter="{Binding}">删除</Hyperlink>
                                </TextBlock>
                            </StackPanel>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#08000000" TargetName="back"/>
                            </Trigger>
                            <DataTrigger Binding="{Binding HasChild}" Value="True">
                                <Setter Property="Visibility" Value="Visible" TargetName="expandBox"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding IsCurrent}" Value="True">
                                <Setter Property="Background" Value="#11000000" TargetName="back"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding MenuId}" Value="0">
                                <Setter Property="Visibility" Value="Collapsed" TargetName="operationPanel"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                    <DataTemplate x:Key="MenuNodeTemplate">
                        <Grid Name="root" Background="Transparent">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="35"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <RadioButton IsChecked="{Binding IsCurrent}" Height="35" Template="{StaticResource ListRowTemplate}" GroupName="item"
                                          Command="{Binding DataContext.ItemSelectedCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}" 
                                          CommandParameter="{Binding}"/>

                            <ItemsControl ItemsSource="{Binding Children}" Grid.Row="1" Margin="20,0,0,0"
                                  ItemTemplate="{DynamicResource MenuNodeTemplate}" Name="childlist" Visibility="Collapsed"/>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded}" Value="True">
                                <Setter Property="Visibility" Value="Visible" TargetName="childlist"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>

                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Margin="20">
        <!--<TextBlock Text="菜单" FontSize="50"/>-->
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Border BorderBrush="#DDD" BorderThickness="0,0,0,1"/>
        <TextBox Text="" VerticalAlignment="Center" Width="300" HorizontalAlignment="Left" Style="{DynamicResource SearchTextBoxStyle}"/>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
            <Button Content="刷新" Style="{StaticResource NormalButtonStyle}" Background="#FF0ABEFF" 
                    Width="70" Margin="5,0"
                    Command="{Binding RefreshCommand}"/>
            <Button Content="添加" 
                Style="{StaticResource IconWithContentButtonStyle}" Width="100"
                Tag="&#xe603;" 
                Command="{Binding AddCommand}"/>
        </StackPanel>

        <Grid Grid.Row="1" Grid.IsSharedSizeScope="True">
            <Grid.RowDefinitions>
                <RowDefinition Height="40"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border Background="#F7F9FA"/>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="*" SharedSizeGroup="column1"/>
                    <ColumnDefinition Width="100" SharedSizeGroup="column2"/>
                    <ColumnDefinition Width="100" SharedSizeGroup="column3"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="菜单名称" VerticalAlignment="Center" Grid.Column="1"/>
                <TextBlock Text="目标视图" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="2"/>
                <TextBlock Text="图标" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="3"/>
                <TextBlock Text="操作" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="4"/>
            </Grid>
            <Border Grid.Row="1" BorderBrush="Red" BorderThickness="2">
                <ItemsControl ItemsSource="{Binding MenuTree}" Grid.Row="1" 
                          ItemTemplate="{StaticResource MenuNodeTemplate}">
                </ItemsControl>
            </Border>
        </Grid>
    </Grid>
</UserControl>
