<Window x:Class="pkNX.WinForms.WPFTextEditor"
        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:pkNX.WinForms"
        mc:Ignorable="d"
        x:Name="Root"
        Background="{StaticResource Window.Background}"
        WindowStartupLocation="CenterScreen"
        Closing="Window_Closing"
        Title="Text Editor" MinWidth="720" MinHeight="405">
    <Window.Resources>
        <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/>
    </Window.Resources>

    <Grid Margin="3">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="443*"/>
            <ColumnDefinition Width="336*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition MinWidth="160" Width="2*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Label Content="Text File:" VerticalAlignment="Center" />
            <ComboBox Grid.Column="1" x:Name="CB_Entry" ItemsSource="{Binding FileNames, ElementName=Root}" MinWidth="152" VerticalAlignment="Center" Margin="3" SelectionChanged="CB_Entry_SelectionChanged"/>

            <StackPanel Grid.Column="2" Orientation="Horizontal" Margin="6,0,0,0">
                <Button x:Name="B_Export" Content="Export (.txt)" Width="90" Margin="3" Click="B_Export_Click" ToolTip="Hold shift while clicking to batch export all files"/>
                <Button x:Name="B_Import" Content="Import (.txt)" Width="90" Margin="3" Click="B_Import_Click"/>
            </StackPanel>

            <StackPanel Grid.Column="4" Orientation="Horizontal" HorizontalAlignment="Right">
                <Label Content="Show hashes:"/>
                <CheckBox x:Name="CHK_ShowHashes" Margin="3,3,6,3" VerticalAlignment="Center" />

                <Button x:Name="B_AddLine" Content="Add Line After" Width="90" Margin="3" Click="B_AddLine_Click"/>
                <Button x:Name="B_RemoveLine" Content="Remove Line" Width="90" Margin="3" Click="B_RemoveLine_Click"/>

                <Button x:Name="B_Save" Content="Save" Width="90" Margin="3" Click="B_Save_Click"/>
            </StackPanel>
        </Grid>

        <DataGrid x:Name="DG_Text" Grid.Row="1" Grid.ColumnSpan="2" Margin="3,4,3,3"
                  IsTextSearchEnabled="True" FontSize="14" AutoGenerateColumns="False"
                  ItemsSource="{Binding Entries, ElementName=Root}"
                  CanUserReorderColumns="False"
                  CellEditEnding="DG_Text_CellEditEnding"
                  d:ItemsSource="{d:SampleData ItemCount=2}" d:SelectedIndex="0">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Line" IsReadOnly="True" Binding="{Binding Line}"/>
                <DataGridTextColumn Header="Variable" Binding="{Binding Variable}"/>
                <DataGridTextColumn Header="Hash" IsReadOnly="True" Binding="{Binding Hash, StringFormat=0x\{0:X16\}}" Visibility="{Binding Source={x:Reference CHK_ShowHashes}, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}"/>
                <DataGridTextColumn Header="Text" Binding="{Binding Text}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
