<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="using:CommunityToolkit.WinUI.Converters"
    xmlns:local="using:RegistryPreviewUILib.HexBox"
    xmlns:skia="using:SkiaSharp.Views.Windows">

    <Style TargetType="local:HexBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:HexBox">
                    <Grid
                        Margin="{TemplateBinding Margin}"
                        Padding="4"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="{TemplateBinding CornerRadius}"
                        IsTabStop="False">
                        <Grid.Resources>
                            <convert:BoolNegationConverter x:Key="BoolNegationConverter" />
                            <local:BigEndianConverter x:Key="BigEndianConverter" />
                            <local:HexboxDataFormatConverter x:Key="HexboxDataFormatConverter" />
                            <local:HexboxDataSignednessConverter x:Key="HexboxDataSignednessConverter" />
                            <local:HexboxDataFormatBoolConverter x:Key="HexboxDataFormatBoolConverter" />
                            <local:HexboxDataTypeConverter x:Key="HexboxDataTypeConverter" />
                            <MenuFlyout x:Key="DataMenuFlyout">
                                <!--  New code for PowerToys implementation  -->
                                <MenuFlyoutItem
                                    x:Uid="/PowerToys.RegistryPreviewUILib/Resources/HexBox_CopyCommand"
                                    Command="{Binding CopyCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="Copy">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="C" Modifiers="Control" />
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    x:Uid="/PowerToys.RegistryPreviewUILib/Resources/HexBox_CopyTextCommand"
                                    Command="{Binding CopyTextCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="Font">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="C" Modifiers="Control,Shift" />
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    x:Uid="/PowerToys.RegistryPreviewUILib/Resources/HexBox_SelectAllCommand"
                                    Command="{Binding SelectAllCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="SelectAll">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="A" Modifiers="Control" />
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <!-- Original source code from HexBox.WinUI.HexBox
                                <MenuFlyoutItem
                                    Command="{Binding CopyCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="Copy"
                                    Text="Copy">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="C" Modifiers="Control" />
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    Command="{Binding CopyTextCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="Font"
                                    Text="Copy text">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="C" Modifiers="Control,Shift"/>
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    Command="{Binding SelectAllCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Icon="SelectAll"
                                    Text="Select all">
                                    <MenuFlyoutItem.KeyboardAccelerators>
                                        <KeyboardAccelerator Key="A" Modifiers="Control" />
                                    </MenuFlyoutItem.KeyboardAccelerators>
                                </MenuFlyoutItem>
                                <MenuFlyoutSeparator />
                                <MenuFlyoutSubItem IsEnabled="{Binding EnforceProperties, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}" Text="Address properties">
                                    <ToggleMenuFlyoutItem IsChecked="{Binding ShowAddress, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource BoolNegationConverter}}" Text="No Address" />
                                </MenuFlyoutSubItem>
                                <MenuFlyoutSubItem IsEnabled="{Binding EnforceProperties, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}" Text="Data properties">
                                    <ToggleMenuFlyoutItem IsChecked="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource BoolNegationConverter}}" Text="No Data" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Int_1}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="1 byte-integer" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Int_2}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="2 byte-integer" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Int_4}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="4 byte-integer" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Int_8}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="8 byte-integer" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Float_32}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="32-bit Floating Point" />
                                    <RadioMenuFlyoutItem
                                        GroupName="DataType"
                                        IsChecked="{Binding DataType, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataTypeConverter}, ConverterParameter=Float_64}"
                                        IsEnabled="{Binding ShowData, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Text="64-bit Floating Point" />
                                    <MenuFlyoutSeparator />
                                    <ToggleMenuFlyoutItem
                                        IsChecked="{Binding DataSignedness, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataSignednessConverter}, ConverterParameter=Signed}"
                                        IsEnabled="{Binding DataFormat, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource HexboxDataFormatBoolConverter}, ConverterParameter={Binding DataFormat}}"
                                        Text="Signed" />
                                    <ToggleMenuFlyoutItem
                                        IsChecked="{Binding DataSignedness, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataSignednessConverter}, ConverterParameter=Unsigned}"
                                        IsEnabled="{Binding DataFormat, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource HexboxDataFormatBoolConverter}, ConverterParameter={Binding DataFormat}}"
                                        Text="Unsigned" />
                                    <MenuFlyoutSeparator />
                                    <ToggleMenuFlyoutItem IsChecked="{Binding DataFormat, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataFormatConverter}, ConverterParameter=Decimal}" Text="Decimal" />
                                    <ToggleMenuFlyoutItem IsChecked="{Binding DataFormat, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource HexboxDataFormatConverter}, ConverterParameter=Hexadecimal}" Text="Hexadecimal" />
                                    <MenuFlyoutSeparator />
                                    <ToggleMenuFlyoutItem IsChecked="{Binding Endianness, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource BigEndianConverter}, ConverterParameter=BigEndian}" Text="Big-Endian" />
                                    <ToggleMenuFlyoutItem IsChecked="{Binding Endianness, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource BigEndianConverter}, ConverterParameter=LittleEndian}" Text="Little-Endian" />
                                </MenuFlyoutSubItem>
                                <MenuFlyoutSubItem IsEnabled="{Binding EnforceProperties, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}" Text="Text properties">
                                    <ToggleMenuFlyoutItem IsChecked="{Binding ShowText, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, Converter={StaticResource BoolNegationConverter}}" Text="No Text" />
                                    <ToggleMenuFlyoutItem
                                        IsChecked="{Binding ShowText, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        IsEnabled="False"
                                        Text="ASCII" />
                                </MenuFlyoutSubItem>-->
                            </MenuFlyout>
                        </Grid.Resources>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="24" />
                        </Grid.ColumnDefinitions>

                        <skia:SKXamlCanvas
                            Name="ElementCanvas"
                            Grid.Column="0"
                            Margin="2,0,2,0"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            ContextFlyout="{StaticResource DataMenuFlyout}" />

                        <ScrollBar
                            Name="ElementScrollBar"
                            Grid.Column="1"
                            Margin="0,0,2,0"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            FontFamily="{TemplateBinding FontFamily}"
                            FontSize="{TemplateBinding FontSize}"
                            IndicatorMode="MouseIndicator"
                            Orientation="Vertical" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
