<local:DependencyCustomListView x:Class="Dependencies.DependencyModuleList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:local="clr-namespace:Dependencies"
        xmlns:properties="clr-namespace:Dependencies.Properties"
        xmlns:util="clr-namespace:Wpf.Util"
        mc:Ignorable="d" 
        d:DesignHeight="300" d:DesignWidth="300"
                                
        Style="{StaticResource DependencyCustomListViewStyle}"
        SearchListFilter="ModuleName"
        CopyHandler="ModuleCopyHandler"
                                
        PreviewMouseLeftButtonUp="OnSelectedModuleChanged"
    >

    <local:DependencyCustomListView.Resources>
        <local:ImageToHeaderConverter x:Key="img"/>
        <local:OverlayImageToHeaderConverter x:Key="img_overlay"/>

        <ContextMenu x:Key="ItemContextMenu">

            <MenuItem Header="Highlight Matching Module In Tree"
                                Command="{Binding DataContext.DoFindModuleInTreeCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                                CommandParameter ="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                                InputGestureText="Ctrl+M"
                                IsEnabled="True" />
            <Separator Height="3" Margin="-1,0,0,0"/>
            <MenuItem HeaderStringFormat= "Copy {0:s}"
                                    Header = "{Binding DataContext.ModuleName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}"
                                    Command="{Binding Path=DataContext.CopyValue, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid},AncestorLevel=1 }}"
                                    CommandParameter ="{Binding DataContext.ModuleName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid }}"
                                    InputGestureText="Ctrl+C"  
                                    IsEnabled="True"/>
            <MenuItem Header="Select All" 
                                Command="ApplicationCommands.SelectAll" 
                                IsEnabled="True"
                                />
            <Separator Height="3" Margin="-1,0,0,0"/>
            <MenuItem x:Name="FullPathItemModules" Header="Full Paths" Height="25" InputGestureText="F9" IsCheckable="True" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=FullPath, Mode=TwoWay}" Margin="0,0,0.2,0"/>
            <Separator Height="3" Margin="-1,0,0,0"/>
            <MenuItem Header="View Module in separate application" 
                                Command="{Binding Path=PlacementTarget.DataContext.OpenNewAppCommand, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                                CommandParameter ="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                                InputGestureText="Maj+Enter"  
                                IsEnabled="True" />
            <MenuItem Header="View Module in Peviewer" 
                                Command="{Binding Path=PlacementTarget.DataContext.OpenPeviewerCommand, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                                CommandParameter ="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                                InputGestureText="Alt+Enter"  
                                IsEnabled="True" />
            <Separator Height="3" Margin="-1,0,0,0"/>
            <MenuItem x:Name="ModuleSearchOrderItem" 
                      Header="View _Module search order" 
                      Command="{Binding DataContext.ConfigureSearchOrderCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                      CommandParameter ="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu} }"
                      InputGestureText="Maj+M" 
                      IsEnabled="True"/>

        </ContextMenu>


    </local:DependencyCustomListView.Resources>

    <local:DependencyCustomListView.View>

        <GridView AllowsColumnReorder="true">
            <GridViewColumn Header="" Width="50" util:GridViewSort.PropertyName="Type">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Grid Margin="0,2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="24" />
                                <ColumnDefinition Width="3" />
                            </Grid.ColumnDefinitions>

                            <Image Grid.Column="0" Width="16" Height="16" Margin="0,0,0,0" Source="{Binding  Filepath, Converter={StaticResource img}}"></Image>
                            <Image Grid.Column="0" Width="16" Height="16" Margin="4,0,0,0" Source="{Binding  Flags, Converter={StaticResource img_overlay}}"></Image>
                        </Grid>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Module" Width="300" DisplayMemberBinding="{Binding ModuleName, TargetNullValue='N/A'}" util:GridViewSort.PropertyName="ModuleName" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Machine"  Width="60" DisplayMemberBinding="{Binding Cpu, TargetNullValue='N/A'}" util:GridViewSort.PropertyName="Cpu" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Type" Width="150" DisplayMemberBinding="{Binding Type, TargetNullValue='N/A'}" util:GridViewSort.PropertyName="Type" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="File Size" Width="100" DisplayMemberBinding="{Binding Filesize, TargetNullValue='N/A', StringFormat={}0x{0:x08}}" util:GridViewSort.PropertyName="FileSize" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Image Base" Width="100" DisplayMemberBinding="{Binding ImageBase, TargetNullValue='N/A', StringFormat={}0x{0:x08}}" util:GridViewSort.PropertyName="ImageBase" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Virtual Size" Width="100" DisplayMemberBinding="{Binding VirtualSize, TargetNullValue='N/A', StringFormat={}0x{0:x08}}" util:GridViewSort.PropertyName="VirtualSize" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Entry point" Width="100" DisplayMemberBinding="{Binding EntryPoint, TargetNullValue='N/A', StringFormat={}0x{0:x08}}" util:GridViewSort.PropertyName="EntryPoint" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Subsystem" Width="100" DisplayMemberBinding="{Binding Subsystem, TargetNullValue='N/A', StringFormat={}0x{0:x08}}" util:GridViewSort.PropertyName="Subsystem" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Subsystem Ver." Width="100" DisplayMemberBinding="{Binding SubsystemVersion, TargetNullValue='N/A'}" util:GridViewSort.PropertyName="SubsystemVersion" HeaderContainerStyle="{StaticResource LeftAlignHeader}"/>
            <GridViewColumn Header="Checksum" Width="200" util:GridViewSort.PropertyName="Checksum" HeaderContainerStyle="{StaticResource LeftAlignHeader}">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock  TextAlignment="Right">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}">
                                    
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding CorrectChecksum , TargetNullValue='False'}" Value="False" >
                                            <Setter Property="Text" Value="{Binding Checksum, StringFormat={}0x{0:x08} (incorrect), TargetNullValue='N/A' }"/>
                                        </DataTrigger>

                                        <DataTrigger Binding="{Binding CorrectChecksum}" Value="True" >
                                            <Setter Property="Text" Value="{Binding Checksum, StringFormat={}0x{0:x08} (correct), TargetNullValue='N/A' }"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </local:DependencyCustomListView.View>
</local:DependencyCustomListView>
