<Page DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Style="{StaticResource A_Style_Page_Generic}"
      mc:Ignorable="d"
      x:Class="ForzaUI.A_RuleTreeMenu"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Page.Resources>
        <!-- Margins inclusive -->
        <System:Double x:Key="A_Double_FullScreenVerticalCarousel_WrapPanelWidth">1540</System:Double>

        <Style x:Key="H_Style_Divider_ComboBoxItem_ListOption" TargetType="local:FZMaterial"
               BasedOn="{StaticResource H_Style_LineBreak_Purple}">
            <Setter Property="Visibility"
                    Value="Visible" />
            <Setter Property="Margin"
                    Value="8,0" />
            <Setter Property="VerticalAlignment"
                    Value="Bottom" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ComboBoxItem}}"
                             Value="True">
                    <Setter Property="Visibility"
                            Value="Hidden" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_ComboBoxItem_ContainerStyle"
               TargetType="ComboBoxItem">
            <!--<Setter Property="FocusSelf.WhenTrue"
                    Value="{Binding (Selector.IsSelected), RelativeSource={RelativeSource Self}}" />
            <Setter Property="local:FocusOnMouseOverBehaviour.Self"
                    Value="True" />-->
            <Setter Property="Margin"
                    Value="0,0,0,0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <local:FZMaterial Color="{StaticResource H_Color_Primary_White}"
                                          x:Name="ComboBoxItem_Background"
                                          MinHeight="32">
                            <Grid>
                                <ContentPresenter />
                            </Grid>
                        </local:FZMaterial>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}"
                                         Value="True">
                                <Setter Property="Color"
                                        TargetName="ComboBoxItem_Background"
                                        Value="{StaticResource H_Color_Primary_Pink}" />
                            </DataTrigger>
                            <Trigger Property="IsMouseOver"
                                     Value="true">
                                <Setter TargetName="ComboBoxItem_Background"
                                        Property="Color"
                                        Value="{StaticResource H_Color_Primary_Pink}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="H_ItemTemplate_RuleComboBoxItemData">
            <Grid MinWidth="612"
                  MinHeight="32">
                <FZTextBlock Text="{Binding Name}"
                             x:Name="ComboBoxItem_Text"
                             Focusable="False"
                             VerticalAlignment="Center"
                             HorizontalAlignment="Center"
                             Margin="8,0,8,0"
                             Color="{StaticResource H_Color_Primary_Purple}"
                             CapHeight="16"
                             FontFamily="Horzion_A" />
                <local:FZMaterial Style="{StaticResource H_Style_Divider_ComboBoxItem_ListOption}"
                                  x:Name="Divider"/>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type ComboBoxItem}}}"
                             Value="True">
                    <Setter Property="Color"
                            TargetName="ComboBoxItem_Text"
                            Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ComboBoxItem}}}"
                         Value="true">
                    <Setter TargetName="ComboBoxItem_Text"
                            Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <!--<Storyboard x:Key="A_Storyboard_ListItem_ToggleFocus">
            <StringAnimationUsingKeyFrames Storyboard.TargetName="AudioEvent"
                                           Storyboard.TargetProperty="(local:AudioEvent.SoundName)">
                <DiscreteStringKeyFrame KeyTime="0:0:0"
                                        Value="" />
                <DiscreteStringKeyFrame KeyTime="0:0:0.01"
                                        Value="/Master/UI/PopUpMenu/HZ2_SFX_HUD_PopUpMenu_Move_01" />
            </StringAnimationUsingKeyFrames>
        </Storyboard>
        <local:AudioEvent x:Name="AudioEvent" />-->


        <Style x:Key="A_Style_FZMaterial_TreeItemBase" TargetType="local:FZMaterial">
            <Setter Property="Color" Value="White"/>
            <Setter Property="Preset"
                    Value="{StaticResource H_Roundtangle_Outer_1px}" />
            <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                        Value="True">
                    <Setter
                        Property="Color"
                        Value="{StaticResource H_Color_Primary_Pink}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding DataContext.ComboBoxData.IsOpened, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                             Value="True">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Pink}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FZRun_RuleTree_HIGHLIGHT"
               TargetType="{x:Type local:FZRun}">
            <Setter Property="Color"
                    Value="{StaticResource H_Color_Primary_Yellow}" />
        </Style>
        <MappingConverter x:Key="A_MappingConverter_RuleTree">
            <MappingConverterEntry Key="{NoCase HIGHLIGHT}" Value="{StaticResource A_Style_FZRun_RuleTree_HIGHLIGHT}" />
        </MappingConverter>
        <Style x:Key="A_Style_FZTextblock_DescriptionField" TargetType="local:FZTextBlock">
            <Setter Property="FontFamily"
                    Value="Horizon_A" />
            <Setter Property="CapHeight"
                    Value="15" />
            <Setter Property="Color"
                    Value="{StaticResource H_Color_Primary_White}" />
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>

        <Style x:Key="A_Style_FZTextBlock_TreeItem_Base" TargetType="local:FZTextBlock">
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Purple}"/>
            <Setter Property="CapHeight" Value="20"/>
            <Setter Property="FontFamily" Value="Horizon_B"/>
            <Setter Property="Text" Value="{Binding Name}"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                             Value="True">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding DataContext.ComboBoxData.IsOpened, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                             Value="True">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_TreeItem"
               TargetType="local:FZTextBlock"
               BasedOn="{StaticResource A_Style_FZTextBlock_TreeItem_Base}">
        </Style>
        <Style x:Key="A_Style_FZTextBlock_TreeItem_Bold"
               TargetType="local:FZTextBlock"
               BasedOn="{StaticResource A_Style_FZTextBlock_TreeItem_Base}">
            <Setter Property="CapHeight"
                    Value="16" />
            <Setter Property="FontFamily"
                    Value="Horizon_A" />
        </Style>

        <local:MappingConverter x:Key="A_MappingConverter_ExpandedState_To_String">
            <local:MappingConverterEntry Key="True"
                                         Value="{local:Loc CustomRules.IDS_CanBeCollapsedSign}" />
            <local:MappingConverterEntry Key="False"
                                         Value="{local:Loc CustomRules.IDS_CanBeExpandedSign}" />
        </local:MappingConverter>

        <Style x:Key="A_Style_FZTextBlock_TreeItem_ExpansionState"
               BasedOn="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}"
               TargetType="local:FZTextBlock">
            <Setter Property="Color"
                    Value="{StaticResource H_Color_Primary_Purple}" />
            <Setter Property="CapHeight"
                    Value="26" />
            <Setter Property="Text"
                    Value="{Binding IsExpanded, Converter={StaticResource A_MappingConverter_ExpandedState_To_String}}" />
            <Setter Property="Visibility"
                    Value="{Binding CanToggleExpanded, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                             Value="True">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Children.Count}"
                             Value="0">
                    <Setter Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_ItemContainerStyle_RuleBase" TargetType="TreeViewItem">
            <Setter Property="Focusable" Value="True" />
            <Setter Property="Margin" Value="0,0,0,0"/>
            <Setter Property="ClipToBounds" Value="False"/>
            <Setter Property="local:ZPanel.ZIndex" Value="0"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="HorizontalContentAlignment"
                    Value="Stretch" />
            <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
            <Setter Property="IsExpanded"
                    Value="{Binding IsExpanded, FallbackValue=True}"/>
            <Setter Property="ItemsSource" Value="{Binding Children}"/>
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin"
                         Value="True">
                    <Trigger.EnterActions>
                        <RaiseRoutedEvent RoutedEvent="Selector.Selected" />
                    </Trigger.EnterActions>
                </Trigger>
                <Trigger Property="Selector.IsSelected"
                         Value="True">
                    <Setter Property="FocusSelf.WhenTrue"
                            Value="True" />
                </Trigger>

                <!--<Trigger Property="IsKeyboardFocusWithin"
                         Value="True">
                    <Trigger.ExitActions>
                        <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                         Storyboard="{StaticResource A_Storyboard_ListItem_ToggleFocus}">
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>-->
            </Style.Triggers>
        </Style>

        <ItemsPanelTemplate x:Key="A_Template_ItemsPanel_Children_Vertical">
            <StackPanel IsItemsHost="True"/>
        </ItemsPanelTemplate>

        <Style x:Key="A_Style_SelectionCommand_Helper" TargetType="ContentPresenter">
            <Setter
                    Property="AttachedRoutedEventCommand.RoutedEvent"
                    Value="UIElement.MouseLeftButtonUp" />
            <Setter
                    Property="AttachedRoutedEventCommand.Command"
                    Value="{Binding SelectCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
        </Style>
        <Style x:Key="A_Style_ItemContainerStyle_EventRule_Children" TargetType="TreeViewItem" BasedOn="{StaticResource A_Style_ItemContainerStyle_RuleBase}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding HasWarning}"
                             Value="True">
                    <Setter Property="ItemsSource"
                            Value="{x:Null}" />
                </DataTrigger>
            </Style.Triggers>
            <Setter Property="ItemsPanel" Value="{StaticResource A_Template_ItemsPanel_Children_Vertical}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                              Margin="0,0,0,0"
                                              IsHitTestVisible="False" />
                            <StackPanel Orientation="Vertical">
                                <!-- tree view item data template -->
                                <ContentPresenter x:Name="PART_Header"
                                                  Style="{StaticResource A_Style_SelectionCommand_Helper}"
                                                  ContentSource="Header"
                                                  Focusable="False"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

                                <!-- children-->
                                <Decorator Visibility="{Binding IsExpanded, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                           x:Name="ItemsContainer">
                                    <ItemsPresenter x:Name="ItemsHost"
                                                    Margin="80,0,0,0" />
                                </Decorator>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <HierarchicalDataTemplate  DataType="{x:Type local:TreeButtonItem}">
            <HierarchicalDataTemplate.Resources>
                <Style x:Key="A_Style_FZMaterial_TreeButtonItem" TargetType="local:FZMaterial" BasedOn="{StaticResource A_Style_FZMaterial_TreeItemBase}">
                    <Setter Property="Color" Value="{StaticResource H_Color_Primary_Blue}"/>
                    <Setter Property="Preset"
                            Value="{StaticResource H_Roundtangle_Outer_3px}" />
                </Style>
            </HierarchicalDataTemplate.Resources>
            <local:FZMaterial x:Name="Background" Style="{StaticResource A_Style_FZMaterial_TreeButtonItem}"
                              HorizontalAlignment="Left"
                              Width="308" Height="32" Margin="0,4,0,0">
                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}" Margin="16, 2" />
            </local:FZMaterial>
        </HierarchicalDataTemplate>

        <Style x:Key="A_Style_TreeItem_ComboBox_CommonBase"
               TargetType="ComboBox">
            <Setter Property="IsTextSearchEnabled"
                    Value="False" />
            <Setter Property="ItemContainerStyle"
                    Value="{StaticResource A_Style_ComboBoxItem_ContainerStyle}" />
            <Setter Property="ItemTemplate"
                    Value="{StaticResource H_ItemTemplate_RuleComboBoxItemData}" />
            <Setter Property="Template"
                    Value="{StaticResource H_Template_ComboBox}" />
            <Setter Property="Focusable"
                    Value="False" />

            <!--<Setter Property="MaxDropDownHeight"
                    Value="612" />-->
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsOpened}"
                             Value="True">
                    <Setter Property="Focusable"
                            Value="True" />
                    <Setter Property="FocusSelf.WhenTrue"
                        Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>


        <Style x:Key="A_Style_TreeItem_ComboBox_HiddenSelection"
               TargetType="ComboBox"
               BasedOn="{StaticResource A_Style_TreeItem_ComboBox_CommonBase}">
            <Style.Resources>
                <Style x:Key="A_Style_FZMaterial_Contained_In_TreeItem"
                       TargetType="local:FZMaterial">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                    <Setter Property="Preset"
                            Value="{StaticResource H_Roundtangle_Outer_1px}" />
                    <Setter Property="HorizontalAlignment"
                            Value="Stretch" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                     Value="True">
                            <Setter Property="Color"
                                    Value="{StaticResource H_Color_Primary_Pink}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Style.Resources>
            <Setter Property="DynamicData.Data">
                <Setter.Value>
                    <DynamicDataSource>
                        <DynamicDataItem Name="ContentSiteStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ContentPresenter"
                                       BasedOn="{StaticResource H_Style_Selected_Content_Default}">
                                    <Setter Property="Visibility"
                                            Value="Collapsed" />
                                    <!--<Setter Property="Visibility"
                                            Value="{Binding SelectionBoxItem, Converter={FZBooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=ComboBox}, FallbackValue=Collapsed}" />-->
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>
                        <DynamicDataItem Name="ToggleButtonStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ToggleButton"
                                       BasedOn="{StaticResource H_Style_Toggle_Button_Default}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <local:FZMaterial x:Name="Background"
                                                                  DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                                                  Style="{StaticResource A_Style_FZMaterial_TreeItemBase}"
                                                                  Height="32"
                                                                  Margin="0,0,0,0">
                                                    <DockPanel HorizontalAlignment="Stretch"
                                                               Margin="16,2">
                                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}"
                                                                           DockPanel.Dock="Left" />
                                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_ExpansionState}"
                                                                           HorizontalAlignment="Right" />
                                                    </DockPanel>
                                                </local:FZMaterial>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>
                    </DynamicDataSource>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="A_Style_TreeItem_RuleParameter_ComboBox_HiddenSelection"
               TargetType="ComboBox"
               BasedOn="{StaticResource A_Style_TreeItem_ComboBox_HiddenSelection}">
            <Setter Property="DynamicData.Data">
                <Setter.Value>
                    <DynamicDataSource>
                        <DynamicDataItem Name="ContentSiteStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ContentPresenter"
                                       BasedOn="{StaticResource H_Style_Selected_Content_Default}">
                                    <Setter Property="Visibility"
                                            Value="Collapsed" />
                                    <!--<Setter Property="Visibility"
                                            Value="{Binding SelectionBoxItem, Converter={FZBooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=ComboBox}, FallbackValue=Collapsed}" />-->
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>

                        <DynamicDataItem Name="ToggleButtonStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ToggleButton"
                                       BasedOn="{StaticResource H_Style_Toggle_Button_Default}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <local:FZMaterial x:Name="Background"
                                                                  DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                                                  Style="{StaticResource A_Style_FZMaterial_TreeItemBase}"
                                                                  Height="32"
                                                                  Margin="0,0,0,0">
                                                    <Grid>
                                                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem}"
                                                                           HorizontalAlignment="Left"
                                                                           Margin="16,2"
                                                                           CapHeight="16"
                                                                           Text="{Binding Value.Name}" />
                                                    </Grid>
                                                </local:FZMaterial>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>
                    </DynamicDataSource>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="A_Style_TreeItem_ComboBox_ConstantButtonState"
               TargetType="ComboBox"
               BasedOn="{StaticResource A_Style_TreeItem_ComboBox_CommonBase}">
            <Style.Resources>
                <Style x:Key="A_Style_FZMaterial_Contained_In_TreeItem"
                       TargetType="local:FZMaterial">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Blue}" />
                    <Setter Property="Preset"
                            Value="{StaticResource H_Roundtangle_Outer_1px}" />
                    <Setter Property="HorizontalAlignment"
                            Value="Stretch" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                     Value="True">
                            <Setter Property="Color"
                                    Value="{StaticResource H_Color_Primary_Pink}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Style.Resources>
            <Setter Property="DynamicData.Data">
                <Setter.Value>
                    <DynamicDataSource>
                        <DynamicDataItem Name="ContentSiteStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ContentPresenter"
                                       BasedOn="{StaticResource H_Style_Selected_Content_Default}">
                                    <Setter Property="Visibility"
                                            Value="Collapsed" />
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>
                        <DynamicDataItem Name="ToggleButtonStyle"
                                         DataType="Style">
                            <DynamicDataItem.Value>
                                <Style TargetType="ToggleButton"
                                       BasedOn="{StaticResource H_Style_Toggle_Button_Default}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <local:FZMaterial x:Name="Background"
                                                                  DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeViewItem}}"
                                                                  Style="{StaticResource A_Style_FZMaterial_Contained_In_TreeItem}"
                                                                  Preset="{StaticResource H_Roundtangle_Outer_3px}"
                                                                  HorizontalAlignment="Left"
                                                                  Width="308"
                                                                  Height="32">
                                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}"
                                                                       Color="{StaticResource H_Color_Primary_White}"
                                                                       Margin="16, 2" />
                                                </local:FZMaterial>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </DynamicDataItem.Value>
                        </DynamicDataItem>
                    </DynamicDataSource>
                </Setter.Value>
            </Setter>
        </Style>
        <HierarchicalDataTemplate  DataType="{x:Type local:TreeButtonComboBoxItem}">
            <Grid Margin="0,4,0,0"
                  Focusable="False">
                <Decorator DataContext="{Binding ComboBoxData}"
                           Focusable="False">
                    <ComboBox ItemsSource="{Binding Items}"
                              AllowReselectionOfItem="{Binding AllowReselection}"
                              IsDropDownOpen="{Binding IsOpened}"
                              SelectedItem="{Binding SelectedItem}"
                              FocusedItemPreview="{Binding FocusedItemPreview}"
                              Style="{StaticResource A_Style_TreeItem_ComboBox_ConstantButtonState}"
                              VerticalAlignment="Top"
                              Height="32" />
                </Decorator>
            </Grid>
        </HierarchicalDataTemplate>


        <HierarchicalDataTemplate DataType="{x:Type local:RuleParameter}">
            <DockPanel Margin="0,4,0,0">
                <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                  Width="308"
                                  Height="32"
                                  DockPanel.Dock="Left"
                                  Preset="{StaticResource H_Roundtangle_Outer_1px}"
                                  IsHitTestVisible="False">
                    <StackPanel Orientation="Horizontal">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem}"
                                           HorizontalAlignment="Left"
                                           CapHeight="16"
                                           Margin="8,0"
                                           Color="{StaticResource H_Color_Primary_White}" />
                        <local:FZMaterial Width="24"
                                          Height="24"
                                          DockPanel.Dock="Right"
                                          ImageSource="/ForzaUI;component/Textures/Data_Bound/EventLab/RulesOfPlay_Warning.png"
                                          Visibility="{Binding HasWarning, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                    </StackPanel>
                </local:FZMaterial>

                <Decorator DataContext="{Binding ComboBoxData}"
                           Focusable="False"
                           Margin="4,0,0,0">
                    <ComboBox ItemsSource="{Binding Items}"
                              AllowReselectionOfItem="{Binding AllowReselection}"
                              IsDropDownOpen="{Binding IsOpened}"
                              SelectedItem="{Binding SelectedItem}"
                              FocusedItemPreview="{Binding FocusedItemPreview}"
                              Style="{StaticResource A_Style_TreeItem_RuleParameter_ComboBox_HiddenSelection}"
                              VerticalAlignment="Top"
                              Height="32" />
                </Decorator>
            </DockPanel>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate DataType="{x:Type local:RuleTrigger}" >
            <Grid Margin="0,4,0,0">
                <Decorator DataContext="{Binding ComboBoxData}"
                           Focusable="False">
                    <ComboBox ItemsSource="{Binding Items}"
                              AllowReselectionOfItem="{Binding AllowReselection}"
                              IsDropDownOpen="{Binding IsOpened}"
                              SelectedItem="{Binding SelectedItem}"
                              FocusedItemPreview="{Binding FocusedItemPreview}"
                              Style="{StaticResource A_Style_TreeItem_ComboBox_HiddenSelection}"
                              VerticalAlignment="Top"
                              Height="32" />
                </Decorator>
            </Grid>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate DataType="{x:Type local:RuleCondition}">
            <Grid Margin="0,4,0,0">
                <Decorator DataContext="{Binding ComboBoxData}"
                           Focusable="False">
                    <ComboBox ItemsSource="{Binding Items}"
                              AllowReselectionOfItem="{Binding AllowReselection}"
                              IsDropDownOpen="{Binding IsOpened}"
                              SelectedItem="{Binding SelectedItem}"
                              FocusedItemPreview="{Binding FocusedItemPreview}"
                              Style="{StaticResource A_Style_TreeItem_ComboBox_HiddenSelection}"
                              VerticalAlignment="Top"
                              Height="32" />
                </Decorator>
            </Grid>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate  DataType="{x:Type local:RuleAction}">
            <Grid Margin="0,4,0,0">
                <Decorator DataContext="{Binding ComboBoxData}"
                           Focusable="False">
                    <ComboBox ItemsSource="{Binding Items}"
                              IsDropDownOpen="{Binding IsOpened}"
                              SelectedItem="{Binding SelectedItem}"
                              FocusedItemPreview="{Binding FocusedItemPreview}"
                              Style="{StaticResource A_Style_TreeItem_ComboBox_HiddenSelection}"
                              VerticalAlignment="Top"
                              Height="32" />
                </Decorator>

            </Grid>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate DataType="{x:Type local:TreeItemContainer}">
            <HierarchicalDataTemplate.Resources>
                <Style x:Key="A_Style_FZMaterial_Wrapper"
                       TargetType="local:FZMaterial"
                       BasedOn="{StaticResource A_Style_FZMaterial_TreeItemBase}">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Purple}" />
                </Style>
                <Style x:Key="A_Style_FZTextBlock_TreeItem_Header"
                       TargetType="local:FZTextBlock"
                       BasedOn="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}">
                    <Setter Property="CapHeight"
                            Value="18" />
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}" />
                </Style>
            </HierarchicalDataTemplate.Resources>
            <Decorator>
                <local:FZMaterial  x:Name="Background"
                                   Style="{StaticResource A_Style_FZMaterial_Wrapper}"
                                   Height="32"
                                   Margin="0,0,0,0">
                    <DockPanel HorizontalAlignment="Stretch"
                               Margin="16,2">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_Header}"
                                           DockPanel.Dock="Left" />
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TreeItem_ExpansionState}"
                                           Color="{StaticResource H_Color_Primary_White}"
                                           HorizontalAlignment="Right" />
                    </DockPanel>
                </local:FZMaterial>
            </Decorator>
        </HierarchicalDataTemplate>

        <Style x:Key="A_Style_FZButton_ButtonSide"
               TargetType="local:FZButton">
            <Setter Property="Width"
                    Value="32" />
            <Setter Property="MinWidth"
                    Value="32" />
            <Setter Property="Height"
                    Value="32" />
            <Setter Property="Margin"
                    Value="2" />
            <Setter Property="VerticalAlignment"
                    Value="Top" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:FZButton">
                        <local:FZMaterial x:Name="Background"
                                          Color="{StaticResource H_Color_Primary_Blue}"
                                          GreedyMeasure="True" Width="32">
                            <!-- todo get icon from art-->
                        </local:FZMaterial>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsKeyboardFocusWithin}"
                                         Value="True">
                                <Setter TargetName="Background"
                                        Property="Color"
                                        Value="{StaticResource H_Color_Primary_Pink}" />
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- EVENT RULE TEMPLATE AND CONTAINER STYLE-->
        
        <DataTemplate DataType="{x:Type local:EventRule}">
            <DataTemplate.Resources>
                <Style x:Key="A_Style_FZMaterial_NotInTree" TargetType="local:FZMaterial">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                        Value="True">
                            <Setter
                        Property="Color"
                        Value="{StaticResource H_Color_Primary_Pink}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
                
                <Style x:Key="A_Style_FZTextBlock_NotInTree_Default" TargetType="local:FZTextBlock">
                    <Setter Property="Color" Value="{StaticResource H_Color_Primary_Purple}"/>
                    <Setter Property="CapHeight" Value="20"/>
                    <Setter Property="Text" Value="{Binding Name}"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                    <Setter Property="FontFamily" Value="Horizon_A" />
                </Style>

                <Style x:Key="A_Style_FZMaterial_Rule_Warning"
                       TargetType="local:FZMaterial">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Purple}" />
                    <Setter Property="ImageSource"
                            Value="/ForzaUI;component/Textures/Data_Bound/EventLab/RulesOfPlay_Warning.png" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                     Value="True">
                            <Setter Property="Color"
                                    Value="{StaticResource H_Color_Primary_White}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>

                <Style x:Key="A_Style_FZMaterial_Rule_SelectionArrow"
                       TargetType="local:FZMaterial">
                    <Setter Property="Data"
                            Value="{StaticResource A_Geometry_SpinnerArrow}" />
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Purple}" />
                    <Setter Property="Visibility"
                            Value="Hidden" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                     Value="True">
                            <Setter Property="Visibility"
                                    Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                     Value="True">
                            <Setter Property="Color"
                                    Value="{StaticResource H_Color_Primary_White}" />
                            <Setter Property="Visibility"
                                    Value="Hidden" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>

            </DataTemplate.Resources>
            <StackPanel Orientation="Horizontal" x:Name="Content">
                <!--<local:FZButton Style="{StaticResource A_Style_FZButton_ButtonSide}"
                                Visibility="{Binding Selector.IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                Command="{Binding InsertRuleCommand, RelativeSource={RelativeSource AncestorType=Page}}"/>-->
                <local:FZMaterial  x:Name="Background"
                                   Style="{StaticResource A_Style_FZMaterial_NotInTree}"
                                   Width="364" Height="32" Margin="2">
                    <DockPanel>
                        <local:FZMaterial x:Name="FZMaterial_Arrow"
                                          DockPanel.Dock="Right"
                                          Style="{StaticResource A_Style_FZMaterial_Rule_SelectionArrow}"
                                          Width="18"
                                          Height="12"
                                          Focusable="False"
                                          Margin="12,0"
                                          RenderTransformOrigin="0.5,0.5">
                            <local:FZMaterial.RenderTransform>
                                <RotateTransform Angle="270" />
                            </local:FZMaterial.RenderTransform>
                        </local:FZMaterial>

                        <local:FZMaterial Width="24"
                                          Height="24"
                                          DockPanel.Dock="Right"
                                          x:Name="Warning"
                                          Style="{StaticResource A_Style_FZMaterial_Rule_Warning}"
                                          Visibility="{Binding HasWarning, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />

                        <Grid>
                            <local:FZTextBlock x:Name="Text"
                                           Style="{StaticResource A_Style_FZTextBlock_NotInTree_Default}"
                                           CapHeight="16"
                                           Margin="16,0,16,0" />
                            <local:FZTextBlock x:Name="Text_Selected"
                                           Style="{StaticResource A_Style_FZTextBlock_NotInTree_Default}"
                                           CapHeight="16"
                                           Visibility="Hidden"
                                           Color="{StaticResource H_Color_Primary_White}"
                                           Margin="16,0,16,0" />
                        </Grid>
                    </DockPanel>
                </local:FZMaterial>
            </StackPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                        Value="True">
                    <Setter
                        Property="Visibility"
                        Value="Visible"
                        TargetName="Text_Selected"/>
                    <Setter
                        Property="Visibility"
                        Value="Hidden"
                        TargetName="Text"/>
                </DataTrigger>

                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding (local:BindingProxy.A), RelativeSource={RelativeSource AncestorType=local:CommonListBox}}"
                                   Value="{StaticResource A_Boolean_True}" />
                        <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                   Value="{StaticResource A_Boolean_False}" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Glass_Purple_40pc}"
                            TargetName="Background" />

                    <Setter
                        Property="Visibility"
                        Value="Visible"
                        TargetName="Text_Selected"/>
                    <Setter
                        Property="Visibility"
                        Value="Hidden"
                        TargetName="Text"/>
                    <Setter Property="Opacity"
                            Value="0.5"
                            TargetName="Text_Selected" />

                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_White}"
                            TargetName="Warning" />
                    <Setter Property="Opacity"
                            Value="0.5"
                            TargetName="Warning" />
                </MultiDataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        
        <Style x:Key="A_Style_ItemContainerStyle_TreeViewItem_Root" TargetType="TreeViewItem" BasedOn="{StaticResource A_Style_ItemContainerStyle_RuleBase}">
            <Setter Property="ItemsPanel" Value="{StaticResource A_Template_ItemsPanel_Children_Vertical}"/>
            <Setter Property="ItemContainerStyle" Value="{StaticResource A_Style_ItemContainerStyle_EventRule_Children}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                              Margin="0,0,0,0"
                                              IsHitTestVisible="False" />

                            <StackPanel Orientation="Vertical">
                                <!-- tree view item data template -->
                                <ContentPresenter x:Name="PART_Header"
                                                  Style="{StaticResource A_Style_SelectionCommand_Helper}"
                                                  ContentSource="Header"
                                                  Focusable="False"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

                                <Decorator x:Name="ItemsContainer"
                                           Visibility="{Binding IsExpanded, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                        <ItemsPresenter x:Name="ItemsHost"
                                                        Margin="80,0,0,0" />
                                </Decorator>
                                <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                                  Height="40"
                                                  Margin="80,0,0,0"
                                                  IsHitTestVisible="False" />
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <ControlTemplate
                x:Key="A_Template_TreeView_FullScreen_Rules"
                TargetType="{Type TreeView}">
            <DockPanel Focusable="False">
                <local:FZScrollViewer Style="{StaticResource A_Style_ScrollViewer_TextMenu}"
                                      CanContentScroll="True"
                                      AllowMouseWheelScrolling="True"
                                      HorizontalScrollBarVisibility="Disabled"
                                      VerticalScrollBarVisibility="{Binding (ScrollViewer.VerticalScrollBarVisibility), RelativeSource={RelativeSource TemplatedParent}}"
                                      IsAtTop="{Binding (local:FZScrollViewer.IsAtTop), Mode=OneWayToSource, RelativeSource={RelativeSource TemplatedParent}}"
                                      IsAtBottom="{Binding (local:FZScrollViewer.IsAtBottom), Mode=OneWayToSource, RelativeSource={RelativeSource TemplatedParent}}"
                                      Height="{TemplateBinding Height}"
                                      Focusable="False"
                                      KeepSelectionOnScreen="True"
                                      Orientation="Vertical"
                                      VerticalAlignment="Stretch"
                                      Margin="0"
                                      x:Name="ScrollViewer">
                    <local:FZScrollViewer.Template>
                        <ControlTemplate TargetType="ScrollViewer">
                            <DockPanel Focusable="False">
                                <ScrollBar DockPanel.Dock="Right"
                                           Minimum="0"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           Maximum="{Binding ScrollableHeight, ElementName=ScrollViewer}"
                                           ViewportSize="{Binding ViewportHeight, ElementName=ScrollViewer}"
                                           Value="{Binding VerticalOffset, ElementName=ScrollViewer}"
                                           Visibility="{Binding ComputedVerticalScrollBarVisibility, ElementName=ScrollViewer}"
                                           Height="{TemplateBinding Height}"
                                           Style="{StaticResource A_Style_ScrollBar_TextMenu}"
                                           Margin="8,0,-24,0"
                                           x:Name="PART_VerticalScrollBar">
                                    <DynamicData.Data>
                                        <DynamicDataSource>
                                            <DynamicDataItem Name="ScrollBarBackgroundMaterial"
                                                             DataType="Style">
                                                <Style TargetType="local:FZMaterial">
                                                    <Setter Property="Color"
                                                            Value="#696969" />
                                                    <Setter Property="Opacity"
                                                            Value="0.8" />
                                                    <Setter Property="Preset">
                                                        <Setter.Value>
                                                            <FZMaterialPresetRoundtangle CornerRadius="4" />
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </DynamicDataItem>
                                        </DynamicDataSource>
                                    </DynamicData.Data>
                                </ScrollBar>
                                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                        Content="{TemplateBinding Content}"
                                                        MaxWidth="1920"
                                                        CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" />
                            </DockPanel>
                        </ControlTemplate>
                    </local:FZScrollViewer.Template>
                    <FZVirtualizingStackPanel Orientation="Vertical"
                                              IsItemsHost="True"
                                              IsVirtualizing="True"
                                              SelectionLimitTop="100"
                                              SelectionLimitBottom="280"
                                              VirtualizationMode="Recycling"
                                              Focusable="False">
                    </FZVirtualizingStackPanel>
                </local:FZScrollViewer>
            </DockPanel>
        </ControlTemplate>

        <System:Double x:Key="A_Double_FullScreenVerticalCarousel_ListHeight">716</System:Double>
        <System:Double x:Key="A_Double_FullScreenVerticalCarousel_ListWidth">900</System:Double>
        <Style x:Key="A_Style_TreeView_FullScreenVerticalStack"
       TargetType="{x:Type TreeView}">
            <Setter Property="Template"
            Value="{StaticResource A_Template_TreeView_FullScreen_Rules}" />
            <Setter Property="VerticalAlignment" 
            Value="Center" />
            <Setter Property="HorizontalAlignment" 
            Value="Left" />
            <Setter Property="ItemContainerStyle"
            Value="{StaticResource A_Style_ItemContainerStyle_TreeViewItem_Root}" />
            <Setter Property="ScrollViewer.CanContentScroll" 
            Value="True" />
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" 
            Value="Auto" />
            <Setter Property="Height" 
            Value="{StaticResource A_Double_FullScreenVerticalCarousel_ListHeight}" />
            <Setter Property="Margin" 
            Value="0" />
            <Setter Property="Width" 
            Value="{StaticResource A_Double_FullScreenVerticalCarousel_ListWidth}" />
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin"
                         Value="False">
                    <Setter Property="Opacity"
                            Value="0.6" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FZButton_IsolatedAddButton" TargetType="local:FZButton">
            <Setter Property="Width"
                    Value="364"/>
            <Setter Property="Height" Value="32"/>
            <Setter Property="Margin"
                    Value="2" />
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:FZButton">
                        <local:FZMaterial x:Name="Background" Color="{StaticResource H_Color_Primary_Blue}"
                                          Preset="{StaticResource H_Roundtangle_Outer_1px}"
                                          GreedyMeasure="True">
                            <local:FZTextBlock Text="{local:Loc CustomRules.IDS_AddRule_MenuButton}"
                                               Color="{StaticResource H_Color_Primary_White}"
                                               Margin="12,0" CapHeight="16"
                                               Style="{StaticResource A_Style_FZTextBlock_TreeItem_Bold}" />
                        </local:FZMaterial>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}"
                                                 Value="True">
                                <Setter TargetName="Background"
                                        Property="Color"
                                        Value="{StaticResource H_Color_Primary_Pink}" />
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <Style x:Key="A_Style_ItemContainerStyle_EventRules"
               TargetType="ContentControl">
            <Style.Setters>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{Type ContentControl}">
                            <Grid>
                                <ContentPresenter x:Name="Content" />
                                <Control x:Name="MouseRollover"
                                     Style="{StaticResource H_Style_TemplatedElement_MouseRollover}" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style.Setters>
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin"
                         Value="True">
                    <Trigger.EnterActions>
                        <RaiseRoutedEvent RoutedEvent="Selector.Selected" />
                    </Trigger.EnterActions>
                </Trigger>
                <Trigger Property="Selector.IsSelected"
                         Value="True">
                    <Setter Property="FocusSelf.WhenTrue"
                            Value="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=local:CommonListBox}}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FZMaterial_EventRule_EmptyItem" TargetType="local:FZMaterial"
               BasedOn="{StaticResource A_Style_FZMaterial_TextMenuEmptyItem}">
            <Setter Property="Height"
                    Value="32" />
            <Setter Property="Margin"
                    Value="2" />
            <Setter Property="Color"
                    Value="{StaticResource H_Color_Glass_Purple_20pc}" />
            <Setter Property="Preset"
                    Value="{StaticResource H_Roundtangle_Outer_3px}" />
        </Style>
        
        <Style x:Key="A_Style_ListBox_RuleMenu"
               TargetType="{x:Type local:CommonListBox}"
               BasedOn="{StaticResource A_Style_ListBox_TextMenu}">
            <Setter Property="ItemContainerStyle"
                    Value="{StaticResource A_Style_ItemContainerStyle_EventRules}" />
            <Setter Property="local:BindingProxy.A"
                    Value="{StaticResource A_Boolean_False}" />
        </Style>

        <local:MappingConverter x:Key="A_MappingConverter_RuleFocus_To_String">
            <local:MappingConverterEntry Key="True"
                                         Value="{local:Loc HelpButtons.IDS_SaveAndExit}" />
            <local:MappingConverterEntry Key="False"
                                         Value="{local:Loc HelpButtons.IDS_Back}" />
        </local:MappingConverter>

        <Style x:Key="A_Style_FZMaterial_RuleMemoryUsageBar"
               TargetType="local:FZMaterial">
            <Setter Property="Visibility"
                    Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding UsageRestrictionPercentage, Converter={CompareConverter}, ConverterParameter=0.0}"
                             Value="{Static CompareResult.GreaterThan}">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Yellow}" />
                    <Setter Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding UsageRestrictionPercentage, Converter={CompareConverter}, ConverterParameter=0.90}"
                             Value="{Static CompareResult.GreaterThan}">
                    <Setter Property="Color"
                            Value="{StaticResource H_Color_Primary_Pink}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <AutoScrollSettings x:Key="A_AutoScrollSettings_DescriptionField" 
            ScrollSeparation="20"
            ScrollOrientation="Vertical"
            Speed="10"
            InitialPause="0:0:0.75"/>

        <Style x:Key="A_Style_FZTextBlock_AutoScroll_DescriptionField" BasedOn="{StaticResource A_Style_FZTextblock_DescriptionField}" TargetType="FZTextBlock" >
            <Setter Property="MarkupConverter" Value="{StaticResource A_MappingConverter_RuleTree}"/>
            <Setter Property="Margin" Value="0,15,28,0"/>
            <Setter Property="AutoScroll" Value="{StaticResource A_AutoScrollSettings_DescriptionField}"/>
            <Setter Property="AutoScroll.AllowScrolling" Value="True"/>
            <Setter Property="Stretch" Value="None"/>

            <Style.Triggers>
            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, ElementName=PART_TreeList}" Value="True">
                <Setter Property="Text" Value="{Binding SelectedTreeItem.Description, RelativeSource={RelativeSource AncestorType=Page}}" />
            </DataTrigger>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding IsKeyboardFocusWithin, ElementName=PART_TreeList}" Value="True" />
                    <Condition Binding="{Binding SelectedTreeItem.ComboBoxData.IsOpened, RelativeSource={RelativeSource AncestorType=Page}}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Text" Value="{Binding SelectedTreeItem.ComboBoxData.FocusedItemPreview.Description, RelativeSource={RelativeSource AncestorType=Page}}" />
            </MultiDataTrigger>
            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, ElementName=PART_RulesList}" Value="True">
                <Setter Property="Text" Value="{local:Loc CustomRules.IDS_Rule_Description_ToolTip}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, ElementName=PART_AddButton}" Value="True">
                <Setter Property="Text" Value="{local:Loc CustomRules.IDS_Rule_Description_ToolTip}" />
            </DataTrigger>
            </Style.Triggers>
        </Style>
        
        <MultiConverter x:Key="H_VisibleIfPercentCondition"
                        ConvertNullValues="True">
            <MultiConverterEntry Converter="{CompareConverter}"
                                 Parameter="0.0"
                                 TargetType="{Type CompareResult}" />
            <MultiConverterEntry>
                <MultiConverterEntry.Converter>
                    <MappingConverter Default="{Static Visibility.Collapsed}">
                        <MappingConverterEntry Key="{Static CompareResult.GreaterThan}"
                                               Value="{Static Visibility.Visible}" />
                    </MappingConverter>
                </MultiConverterEntry.Converter>
            </MultiConverterEntry>
        </MultiConverter>

        <MultiConverter x:Key="H_ScaleNormalizedValueIntoPercentageText"
                        ConvertNullValues="True">
            <MultiConverterEntry Converter="{MathOperationConverter Operation=Multiply}"
                                 TargetType="float">
                <MultiConverterEntry.Parameter>
                    <Double>100</Double>
                </MultiConverterEntry.Parameter>
            </MultiConverterEntry>
            <MultiConverterEntry Converter="{StaticResource A_NumUnitConverter_ShowUnit_0dp}"
                                 Parameter="percentage"
                                 TargetType="Double" />
        </MultiConverter>
        <ExponentialEase x:Key="A_EasingFunction_ProgressBar_BlendValue_MemoryUsage"
                         EasingMode="EaseIn" />
        <local:UIStoryboard x:Key="A_Storyboard_ProgressBar_BlendValueInputChanged_MemoryUsage">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="{x:Null}"
                                           FillBehavior="HoldEnd"
                                           Storyboard.TargetProperty="(local:BlendValue.Blend)">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                        Value="0" />
                <EasingDoubleKeyFrame KeyTime="{StaticResource A_KeyTime_ProgressBar_CareerProgression_BlendValueEnd_Relative}"
                                      Value="1"
                                      EasingFunction="{StaticResource A_EasingFunction_ProgressBar_BlendValue_MemoryUsage}" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>
    </Page.Resources>
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}"/>
    </local:UIPageTransitionManager.TransitionManager>
    <Grid x:Name="PART_LayoutRoot">
        <Control x:Name="DefaultBackground"
                 Focusable="False"
                 Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                <Control Template="{StaticResource A_Style_Control_ScreenBackground}" />

                <Decorator HorizontalAlignment="Center"
                           Margin="22,0,22,40"
                           VerticalAlignment="Center"
                           Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_1}">

                    <StackPanel Orientation="Vertical">
                        <ContentControl Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                        Content="{local:Loc ScreenTitles.IDS_RulesOfPlay}"
                                        Width="364"
                                        local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Blueprint.png"
                                        HorizontalAlignment="Left" />

                        <StackPanel Orientation="Horizontal">
                            <Grid Margin="0,-2,28,0">
                                <DockPanel MaxHeight="720">
                                    <StackPanel Orientation="Vertical"
                                                DockPanel.Dock="Top"
                                                x:Name="RuleContainer"
                                                KeyboardNavigation.DirectionalNavigation="Contained">
                                        <local:CommonListBox ItemsSource="{Binding TreeData.Rules}"
                                                             Style="{StaticResource A_Style_ListBox_RuleMenu}"
                                                             SelectedItem="{Binding SelectedRuleItem}"
                                                             local:BindingProxy.A="{Binding IsKeyboardFocusWithin, ElementName=PART_TreeList, FallbackValue={StaticResource A_Boolean_False}}"
                                                             x:Name="PART_RulesList"
                                                             VerticalAlignment="Top"
                                                             MaxHeight="684"
                                                             KeyboardNavigation.DirectionalNavigation="Continue"
                                                             local:AttachedRoutedEventCommand.Command="{Binding OnElementGotFocusEvent, RelativeSource={RelativeSource AncestorType=Page}}"
                                                             local:AttachedRoutedEventCommand.RoutedEvent="Selector.GotFocus"
                                                             Focusable="True" />
                                        <local:FZButton Style="{StaticResource A_Style_FZButton_IsolatedAddButton}"
                                                        x:Name="PART_AddButton"
                                                        Command="{Binding AddRuleCommand, RelativeSource={RelativeSource AncestorType=Page}}"
                                                        local:AttachedRoutedEventCommand.Command="{Binding OnElementGotFocusEvent, RelativeSource={RelativeSource AncestorType=Page}}"
                                                        local:AttachedRoutedEventCommand.RoutedEvent="FrameworkElement.GotFocus" />
                                    </StackPanel>
                                    <!-- List of empty items that only fill the available space so as not to impact the navigation contained items-->
                                    <ItemsControl VerticalAlignment="Bottom"
                                                  Focusable="False">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <Grid ClipToBounds="True">
                                                    <StackPanel Orientation="Vertical"
                                                                IsItemsHost="True" />
                                                </Grid>
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_EventRule_EmptyItem}" />
                                    </ItemsControl>
                                </DockPanel>
                            </Grid>

                            <Decorator Focusable="False">
                                <TreeView ItemsSource="{Binding Children}"
                                      DataContext="{Binding SelectedRuleItem}"
                                      Style="{StaticResource A_Style_TreeView_FullScreenVerticalStack}"
                                      KeyboardNavigation.DirectionalNavigation="Contained"
                                      VirtualizingStackPanel.IsVirtualizing="True"
                                      VirtualizingStackPanel.VirtualizationMode="Recycling"
                                      local:AttachedRoutedEventCommand.Command="{Binding OnSelectionChangedEvent, RelativeSource={RelativeSource AncestorType=Page}}"
                                      local:AttachedRoutedEventCommand.RoutedEvent="TreeView.SelectedItemChanged"
                                      local:AttachedRoutedEventCommand2.Command="{Binding OnElementGotFocusEvent, RelativeSource={RelativeSource AncestorType=Page}}"
                                      local:AttachedRoutedEventCommand2.RoutedEvent="TreeView.GotFocus"
                                      x:Name="PART_TreeList">
                                </TreeView>
                            </Decorator>
                        </StackPanel>

                        <Decorator x:Name="DescriptionField">
                            <local:FZMaterial Height="76"
                                              Width="1296"
                                              Margin="0,20,0,24"
                                              Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                              Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"
                                              HorizontalAlignment="Stretch">
                                <DockPanel>
                                    <local:FZMaterial Width="32"
                                                      Height="32"
                                                      Margin="12,12,16,0"
                                                      DockPanel.Dock="Left"
                                                      VerticalAlignment="Top"
                                                      ImageSource="/ForzaUI;component/Textures/Data_Bound/EventLab/RulesOfPlay_Information.png" />
                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_AutoScroll_DescriptionField}"/>
                                </DockPanel>
                            </local:FZMaterial>
                        </Decorator>
                    </StackPanel>
                </Decorator>

                <StackPanel Orientation="Vertical"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Top"
                            Focusable="False"
                            IsHitTestVisible="False"
                            Margin="0,64,312,0"
                            Visibility="{Binding UsageRestrictionPercentage,Converter={StaticResource H_VisibleIfPercentCondition}}">
                    <local:FZTextBlock Text="{Binding UsageRestrictionName}"
                                       FontFamily="Horizon_A"
                                       CapHeight="16"
                                       Margin="0,0,0,8"
                                       Color="{StaticResource H_Color_Primary_White}"
                                       HorizontalAlignment="Right" />

                    <Grid HorizontalAlignment="Right">
                        <DockPanel Width="364"
                                   Height="32">

                            <ProgressBar x:Name="ProgressBar"
                                         Width="364"
                                         local:BlendValue.Input="{Binding UsageRestrictionPercentage}"
                                         local:BlendValue.ShouldSkipInitialInputChange="False"
                                         local:BlendValue.InputChangedStoryboard="{StaticResource A_Storyboard_ProgressBar_BlendValueInputChanged_MemoryUsage}"
                                         Value="{Binding (local:BlendValue.Output), RelativeSource={RelativeSource Self}}"
                                         Minimum="0"
                                         Maximum="1">
                                <ProgressBar.Template>
                                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                                        <DockPanel>
                                            <local:FZMaterial x:Name="endOfProgressBar_visual"
                                                              DockPanel.Dock="Right"
                                                              Height="32"
                                                              Style="{StaticResource A_Style_FZMaterial_EndOfProgressBar_Visual}" />
                                            <Grid>
                                                <local:FZMaterial Color="{StaticResource H_Color_Glass_Purple_40pc}"
                                                                  Height="32"
                                                                  x:Name="PART_Track"
                                                                  Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll3px}" />

                                                <Grid x:Name="PART_Indicator"
                                                      HorizontalAlignment="Left"
                                                      ClipToBounds="True">
                                                    <local:FZMaterial Width="{TemplateBinding ActualWidth}"
                                                                      Style="{StaticResource A_Style_FZMaterial_RuleMemoryUsageBar}"
                                                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll3px}" />
                                                </Grid>
                                            </Grid>
                                        </DockPanel>
                                    </ControlTemplate>
                                </ProgressBar.Template>
                            </ProgressBar>
                        </DockPanel>

                        <!-- percentage text -->
                        <local:FZTextBlock Text="{Binding UsageRestrictionPercentage, Converter={StaticResource H_ScaleNormalizedValueIntoPercentageText}}"
                                           CapHeight="18"
                                           HorizontalAlignment="Right"
                                           VerticalAlignment="Center"
                                           Margin="0,0,8,0">
                            <local:FZTextBlock.Style>
                                <Style TargetType="local:FZTextBlock">
                                    <Setter Property="FontFamily"
                                            Value="Horizon_B" />
                                    <Setter Property="Margin"
                                            Value="0,0,0,-1" />
                                    <Setter Property="Color"
                                            Value="{StaticResource A_Color_HUD_Text}" /> />
                                </Style>
                            </local:FZTextBlock.Style>
                        </local:FZTextBlock>
                    </Grid>
                </StackPanel>
            </Grid>
        </Grid>

        <PageInputHandler x:Name="MoreOptionsInput"
                          Command="{Binding MoreOptionsCommand}"
                          Button="Start" />
        <PageInputHandler x:Name="CollapseInput"
                          Command="{Binding CollapseTreeItemCommand}"
                          Button="LTrigger" />
        <PageInputHandler x:Name="ExpandInput"
                          Command="{Binding ExpandTreeItemCommand}"
                          Button="RTrigger" />
        <PageInputHandler x:Name="BackInput"
                          Command="{Binding OpenRuleImportCommand}"
                          Button="Back" />
        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Select}" />
                <local:ControllerButtonControl Button="B"
                                               Description="{Binding IsKeyboardFocusWithin, ElementName=RuleContainer, Converter={StaticResource A_MappingConverter_RuleFocus_To_String}}" />
                <local:ControllerButtonControl Button="Start"
                                               Visibility="{Binding Command.Enabled, ElementName=MoreOptionsInput, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                               Description="{local:Loc HelpButtons.IDS_MoreOptions}" />
                <local:ControllerButtonControl Button="LTrigger"
                                               Visibility="{Binding Command.Enabled, ElementName=CollapseInput, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                               Description="{local:Loc HelpButtons.IDS_Collapse}" />
                <local:ControllerButtonControl Button="RTrigger"
                                               Visibility="{Binding Command.Enabled, ElementName=ExpandInput, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                               Description="{local:Loc HelpButtons.IDS_Expand}" />
                <local:ControllerButtonControl Button="Back"
                                               Description="{local:Loc HelpButtons.IDS_ImportEventRuleSet}" />
                <local:ControllerButtonControl Button="X"
                                               Visibility="{Binding CanPreviewSelection, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                               Description="{local:Loc HelpButtons.IDS_PreviewEventLabSound}" />
            </local:ControllerButtonPanel>
        </ContentControl>
    </Grid>
</Page>
