<Window x:Class="AdvancedCalculator.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:AdvancedCalculator"
        mc:Ignorable="d"
        Title="Advanced Calculator" Height="450" Width="800" Icon="calculator-variant-black.png">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="3*" />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition x:Name="rdFxDefinitions" Height="0" />
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" x:Name="lvVariableList" HorizontalContentAlignment="Stretch">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{Binding Path=ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" FontFamily="{StaticResource MDI}" FontSize="24" Text="{Binding Icon}" VerticalAlignment="Center" />
                            <TextBlock Grid.Column="1" Text="{Binding VariableName}" FontWeight="Bold" />
                            <StackPanel Grid.Column="2">
                                <TextBlock Text="{Binding Value}" />
                                <TextBlock Visibility="{Binding ExpressionVisibility}" Text="{Binding ExpressionComputation}" FontStyle="Italic" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <ListView Grid.Row="1" x:Name="lvFxDefinitions" ItemsSource="{x:Static local:FunctionDefinitonItem.DefinedFunctions}">
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListViewItem}">
                                    <ContentPresenter />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock FontFamily="{StaticResource MDI}" Text="{Binding Icon}" Margin="5,0" />
                                <TextBlock Text="{Binding FunctionName}" FontWeight="Bold" />
                            </StackPanel>
                            <TextBlock Text="{Binding FunctionDescription}" FontStyle="Italic" />
                            <ListView Margin="5,0" ItemsSource="{Binding FunctionArguments}" BorderThickness="0">
                                <ListView.ItemContainerStyle>
                                    <Style TargetType="{x:Type ListViewItem}">
                                        <Setter Property="Background" Value="Transparent" />
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ListViewItem}">
                                                    <ContentPresenter />
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListView.ItemContainerStyle>
                                <ListView.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <TextBlock Text="{Binding Key}" />
                                            <TextBlock Text="{Binding Value}" FontStyle="Italic" Margin="5,0,0,0" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
        <GridSplitter Grid.Column="0" HorizontalAlignment="Right" Height="100" VerticalAlignment="Center" Width="5" />
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" x:Name="lvHistory">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel VerticalAlignment="Bottom" />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{Binding Path=ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static local:IconFont.ArrowRightDropCircle}" FontSize="24" VerticalAlignment="Center" />
                            <StackPanel Grid.Column="1">
                                <TextBlock Text="{Binding Input}" />
                                <TextBlock Text="{Binding Output}" FontWeight="Bold" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Button x:Name="btnFx" Width="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" Margin="5" Click="btnFx_Click">
                    <TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static local:IconFont.FunctionVariant}" />
                </Button>
                <TextBox Grid.Column="1" x:Name="txtInput" Margin="10" KeyDown="txtInput_KeyDown" />
            </Grid>
        </Grid>
    </Grid>
</Window>