<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c1="using:C1.Xaml"
    xmlns:c1exp="using:C1.Xaml.ExpressionEditor">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ms-appx:///C1.UWP/themes/C1Button.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <c1:VisibilityConverter x:Key="VisibilityConverter"/>
    <c1exp:ArgumentConverter x:Key="ArgumentConverter" />
    <c1exp:SelectItemConverter x:Key="SelectItemConverter"/>
    
    <c1exp:RuleCollection x:Key="Rules">
        <c1exp:NumberRule Foreground="Blue" />
        <c1exp:StringRule Foreground="Red" />
        <c1exp:FieldRule Foreground="Purple" />
        <c1exp:FunctionsRule Foreground="Green" />
    </c1exp:RuleCollection>

    <Style x:Key="IntellisenseBoxStyle" TargetType="ListBox">
        <Setter Property="BorderBrush" Value="{ThemeResource AppBarBorderThemeBrush}"/>
        <Setter Property="BorderThickness" Value="1" />
    </Style>

    <Style x:Key="listboxItemStyle" TargetType="ListBoxItem">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="TabNavigation" Value="Local" />
        <Setter Property="Padding" Value="12,11,12,13" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="UseSystemFocusVisuals" Value="True" />
        <Setter Property="MinWidth" Value="200" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Grid
                        x:Name="LayoutRoot"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        >
                        <Grid.Resources>
                            <Style x:Key="BaseContentPresenterStyle" TargetType="ContentPresenter">
                                <Setter Property="FontFamily" Value="XamlAutoFontFamily" />
                                <Setter Property="FontWeight" Value="SemiBold" />
                                <Setter Property="FontSize" Value="15" />
                                <Setter Property="TextWrapping" Value="Wrap" />
                                <Setter Property="LineStackingStrategy" Value="MaxHeight" />
                                <Setter Property="TextLineBounds" Value="Full" />
                                <Setter Property="OpticalMarginAlignment" Value="TrimSideBearings" />
                            </Style>
                            <Style x:Key="BodyContentPresenterStyle" TargetType="ContentPresenter" BasedOn="{StaticResource BaseContentPresenterStyle}">
                                <Setter Property="FontWeight" Value="Normal" />
                                <Setter Property="FontSize" Value="15" />
                            </Style>
                        </Grid.Resources>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListMediumBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedPointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentMediumBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedPressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground"
                                               Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                               Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle
                            x:Name="PressedBackground"
                            Fill="Transparent"
                            Control.IsTemplateFocusTarget="True"/>
                        <ContentPresenter
                            x:Name="ContentPresenter"
                            ContentTransitions="{TemplateBinding ContentTransitions}"
                            Style="{StaticResource BodyContentPresenterStyle}"
                            TextWrapping="NoWrap"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}" >
                            <ContentPresenter.ContentTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" MaxWidth="16" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <Image HorizontalAlignment="Left" Width="Auto" MaxWidth="16">
                                            <Image.Source>
                                                <BitmapImage UriSource="{Binding Icon}" />
                                            </Image.Source>
                                        </Image>
                                        <TextBlock Grid.Column="1" Text="{Binding Item.Name}" />
                                    </Grid>
                                </DataTemplate>
                            </ContentPresenter.ContentTemplate>
                        </ContentPresenter>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <!-- Style C1ExpressionRichTextBox -->
    <Style TargetType="c1exp:C1ExpressionRichTextBox">
        <Setter Property="ExpressionRules" Value="{StaticResource Rules}" />
        <Setter Property="IsSpellCheckEnabled" Value="False" />
        <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}"/>
        <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}"/>
        <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
        <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}"/>
        <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}"/>
        <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}"/>
        <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/>
        <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
        <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
        <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="c1exp:C1ExpressionRichTextBox">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BorderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="RequestedTheme" Storyboard.TargetName="ContentElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Light"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" Margin="{TemplateBinding BorderThickness}" Opacity="{ThemeResource TextControlBackgroundRestOpacity}" Grid.Row="1" Grid.RowSpan="1"/>
                        <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="1"/>
                        <ContentPresenter x:Name="HeaderContentPresenter" Grid.ColumnSpan="2" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}" FontWeight="Normal" Margin="0,0,0,8" Grid.Row="0" Visibility="Collapsed" x:DeferLoadStrategy="Lazy"/>
                        <ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Row="1" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled"/>
                        <ContentControl x:Name="PlaceholderTextContentPresenter" Grid.ColumnSpan="2" Content="{TemplateBinding PlaceholderText}" Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}" IsHitTestVisible="False" IsTabStop="False" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Row="1"/>
                        <Popup x:Name="IntellisensePopup">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <ListBox Name="IntellisenseBox" MaxHeight="200" ItemContainerStyle="{StaticResource listboxItemStyle}" Style="{StaticResource IntellisenseBoxStyle}" />
                                <Popup IsOpen="{Binding ElementName=IntellisenseBox,Path=SelectedItem,Converter={StaticResource SelectItemConverter}}" Grid.Column="1" HorizontalOffset="10">
                                    <Border BorderBrush="LightGray" BorderThickness="1" CornerRadius="1" Background="White">
                                        <TextBlock Foreground="Black" MaxWidth="300" TextWrapping="Wrap" DataContext="{Binding ElementName=IntellisenseBox,Path=SelectedItem}">
                                    <Run Text="{Binding Item.Name}" FontWeight="Bold" Foreground="Green" />
                                    <Run Text="{Binding ItemArguments, Mode=OneWay}" FontStyle="Italic" Foreground="Magenta" />
                                    <LineBreak />
                                    <Run Text="{Binding Item.Description}" />
                                        </TextBlock>
                                    </Border>
                                </Popup>
                            </Grid>
                        </Popup>
                        <ToolTipService.ToolTip>
                            <ToolTip x:Name="DescriptionToolTip" Placement="Left"/>
                        </ToolTipService.ToolTip>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Style C1ExpressionEditor -->
    <Style TargetType="c1exp:C1ExpressionEditor">
        <Setter Property="BorderBrush" Value="{ThemeResource AppBarBorderThemeBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Height" Value="100"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="c1exp:C1ExpressionEditor">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <c1exp:C1ExpressionRichTextBox x:Name="ExpressionTextBox" Text="{Binding Expression, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}" Foreground="{TemplateBinding Foreground}" Background="{TemplateBinding Background}" UnderlineErrors="{TemplateBinding UnderlineErrors}" SyntaxHighlighting="{TemplateBinding SyntaxHighlighting}" />
                            <Border Grid.Row="1" BorderBrush="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" BorderThickness="2,0,2,2" Visibility="{Binding ShowErrorBox, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource VisibilityConverter}}">
                                <TextBlock x:Name="ExpressionErrorText" Foreground="Red" />
                            </Border>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Style C1ExpressionEditorPanel -->
    <Style TargetType="c1exp:C1ExpressionEditorPanel">
        <Setter Property="MouseOverBrush" Value="{ThemeResource SystemControlBackgroundBaseMediumBrush}" />
        <Setter Property="PressedBrush" Value="{ThemeResource SystemControlBackgroundBaseMediumBrush}" />
        <Setter Property="ButtonBackground" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}"/>
        <Setter Property="ButtonForeground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="c1exp:C1ExpressionEditorPanel">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Path1" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="Path2" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="Path3" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="Path4" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="Path5" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,0">
                                    <c1:C1UniformGrid HorizontalAlignment="Center" Rows="2" >
                                        <c1:C1UniformGrid.Resources>
                                            <Style TargetType="Button" BasedOn="{StaticResource ClearStyleButtonStyle}">
                                                <Setter Property="Width" Value="33"></Setter>
                                                <Setter Property="Height" Value="33"></Setter>
                                                <Setter Property="Margin" Value="4"></Setter>
                                                <Setter Property="FontFamily" Value="Segoe UI"></Setter>
                                                <Setter Property="FontSize" Value="11"></Setter>
                                                <Setter Property="FontStyle" Value="Normal"></Setter>
                                                <Setter Property="FontWeight" Value="Normal"></Setter>
                                                <Setter Property="Padding" Value="1"></Setter>
                                            </Style>
                                        </c1:C1UniformGrid.Resources>
                                        <Button CommandParameter=" + " Content="&#xE948;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" - " Content="&#xE949;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" * " Content="&#xE947;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" / " Content="&#xE94A;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" Mod " Content="&#xE94C;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" = " Content="&#xE94E;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter=" &lt;&gt; " Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" >
                                            <Path x:Name="Path1" Data="M6.8438272,0L6.0373545,2.0623121 8,2.0623121 8,4.0623121 5.2552485,4.0623121 4.8641958,5.0623121 8,5.0623121 8,7.0623121 4.0820904,7.0623121 3.2790608,9.115819 1.1248636,9.0938644 1.9289982,7.0623121 0,7.0623121 0,5.0623121 2.7206435,5.0623121 3.116466,4.0623121 2.7167258E-07,4.0623121 2.7167258E-07,2.0623121 3.9081113,2.0623121 4.7207074,0.0093827248z" Fill="{TemplateBinding ButtonForeground}" Height="9" Stretch="Fill" Width="8"/>
                                        </Button>
                                        <Button CommandParameter=" &lt; " Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" >
                                            <Path x:Name="Path2" Data="F1M14.10388,3.5915833L10.967,3.579 6.4790001,8.066 10.967,12.554 14.128588,12.56459 9.5209999,8.066z" Fill="{TemplateBinding ButtonForeground}" Height="8" Stretch="Fill" Width="6"/>
                                        </Button>
                                        <Button CommandParameter=" &gt; " Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" >
                                            <Path x:Name="Path3" Data="F1M14.10388,3.5915833L10.967,3.579 6.4790001,8.066 10.967,12.554 14.128588,12.56459 9.5209999,8.066z" Fill="{TemplateBinding ButtonForeground}" Height="8" RenderTransformOrigin="0.5,0.5" Stretch="Fill" Width="6">
                                                <Path.RenderTransform>
                                                    <TransformGroup>
                                                        <RotateTransform Angle="-180"/>
                                                    </TransformGroup>
                                                </Path.RenderTransform>
                                            </Path>
                                        </Button>
                                        <Button CommandParameter=" &lt;= " Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" >
                                            <Path x:Name="Path4" Data="M7.0000005,5L12.000001,5 12.000001,7 7.0000005,7z M7.0000005,1.9999996L12.000001,1.9999996 12.000001,3.9999998 7.0000005,3.9999998z M3.5201895,0L5.9806204,0.011203052 2.3860106,3.9948406 6,8.000001 3.5201895,7.9905715 0,3.9948406z" Fill="{TemplateBinding ButtonForeground}" Height="8" Stretch="Fill" Width="12"/>
                                        </Button>
                                        <Button CommandParameter=" &gt;= " Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" >
                                            <Path x:Name="Path5" Data="M0,4L5,4 5,6 0,6z M0,0.99999988L5,0.99999988 5,3 0,3z M9.5201912,0L11.980621,0.011203052 8.3860121,3.9948406 12.000002,8.000001 9.5201912,7.9905715 6.0000014,3.9948406z" Height="8" Margin="-1" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding ButtonForeground}" Stretch="Fill" Width="12">
                                                <Path.RenderTransform>
                                                    <TransformGroup>
                                                        <RotateTransform Angle="-180"/>
                                                    </TransformGroup>
                                                </Path.RenderTransform>
                                            </Path>
                                        </Button>
                                        <Button Content="And" CommandParameter=" And " Width="40" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button Content="Or" CommandParameter=" Or " Width="40" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button Content="Not" CommandParameter=" Not " Width="40" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                        <Button CommandParameter="&#34;" Content="&#xE9B1;" FontFamily="Segoe MDL2 Assets" FontWeight="ExtraBold" Command="{Binding InsertItem}" Background="{TemplateBinding ButtonBackground}" Foreground="{TemplateBinding ButtonForeground}" c1:ClearStyleExtensions.MouseOverBrush="{TemplateBinding MouseOverBrush}" c1:ClearStyleExtensions.PressedBrush="{TemplateBinding PressedBrush}" />
                                    </c1:C1UniformGrid>
                                </Border>
                                <Grid Grid.Row="1">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="120"/>
                                        <RowDefinition MinHeight="50"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="3*"/>
                                        <ColumnDefinition Width="4*"/>
                                    </Grid.ColumnDefinitions>
                                    <c1:C1TreeView x:Name="CategoriesTreeView" Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}" ItemsSource="{Binding Categories}" FontSize="{TemplateBinding FontSize}">
                                        <c1:C1TreeView.ItemTemplate>
                                            <c1:C1HierarchicalDataTemplate ItemsSource="{Binding SubGroups}">
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding GroupName}"/>
                                                </DataTemplate>
                                            </c1:C1HierarchicalDataTemplate>
                                        </c1:C1TreeView.ItemTemplate>
                                    </c1:C1TreeView>
                                    <ListBox x:Name="ItemsListBox" Grid.Column="1" ItemsSource="{Binding SelectedItem.DataContext.Items, ElementName=CategoriesTreeView}" FontSize="{TemplateBinding FontSize}">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Definition}" FontSize="{Binding FontSize, ElementName=ItemsListBox}"></TextBlock>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                    <Border  Grid.Row="1" Grid.ColumnSpan="2">
                                        <Grid Margin="5">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <TextBlock Foreground="{TemplateBinding Foreground}" FontWeight="Bold" Text="{Binding SelectedItem.Definition, ElementName=ItemsListBox}"/>
                                            <TextBlock Foreground="{TemplateBinding Foreground}" Grid.Row="1" TextWrapping="Wrap" Text="{Binding SelectedItem.Description, ElementName=ItemsListBox}"/>
                                            <TextBlock Foreground="{TemplateBinding Foreground}" Grid.Row="2" TextWrapping="Wrap" Text="{Binding SelectedItem, ElementName=ItemsListBox, Converter={StaticResource ArgumentConverter}}"/>
                                        </Grid>
                                    </Border>
                                </Grid>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>