<UserControl x:Class="NETworkManager.Views.TracerouteView"
        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:Converter="clr-namespace:NETworkManager.Converters"
        xmlns:WpfHelper="clr-namespace:NETworkManager.WpfHelper"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"        
        xmlns:Validator="clr-namespace:NETworkManager.Validators"
        xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"             
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        Loaded="UserControl_Loaded"
        mc:Ignorable="d">
    <UserControl.Resources>
        <Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
        <Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converter:BooleanReverseToVisibilityConverter x:Key="BooleanReverseToVisibilityConverter" />
        <Converter:IntToStringConverter x:Key="IntToStringConverter" />
        <Converter:IPAddressToStringConverter x:Key="IPAddressToStringConverter" />
        <Converter:IPStatusToStringConverter x:Key="IPStatusToStringConverter" />
        <Converter:NullableDateTimeToStringConverter x:Key="NullableDateTimeToStringConverter" />
        <Converter:PingTimeToStringConverter x:Key="PingTimeToStringConverter" />
        <Converter:StringIsNotNullOrEmptyToBoolConverter x:Key="StringIsNotNullOrEmptyToBoolConverter" />
    </UserControl.Resources>
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Destination}" />
        <Grid Grid.Row="1" Margin="0,0,0,20">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{DynamicResource String_Host}" Style="{DynamicResource DefaultTextBlock}" VerticalAlignment="Center" />
                <ComboBox Grid.Column="2" x:Name="txtHost" ItemsSource="{Binding HostHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleHostnameOrIPAddress}" IsEnabled="{Binding IsTraceRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource HistoryComboBox}">
                    <ComboBox.Text>
                        <Binding Path="Host" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                            </Binding.ValidationRules>
                        </Binding>
                    </ComboBox.Text>
                </ComboBox>
                <Button Grid.Column="4" Command="{Binding TraceCommand}" IsDefault="{Binding IsTraceRunning,Converter={StaticResource BooleanReverseConverter}}" IsCancel="{Binding IsTraceRunning}" HorizontalAlignment="Right">
                    <Button.Resources>
                        <Style TargetType="{x:Type Button}" BasedOn="{StaticResource ImageWithTextButton}">
                            <Setter Property="IsEnabled" Value="True" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=txtHost}" Value="True" >
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding CancelTrace}" Value="True">
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Resources>
                    <Button.Content>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Rectangle Width="20" Height="20" Margin="10,5,0,5">
                                <Rectangle.Resources>
                                    <VisualBrush x:Key="VisualControlPlay" Stretch="Uniform" Visual="{IconPacks:Material Kind=Play}" />
                                    <VisualBrush x:Key="VisualClose" Stretch="Uniform" Visual="{IconPacks:Material Kind=Close}" />
                                </Rectangle.Resources>
                                <Rectangle.Style>
                                    <Style TargetType="{x:Type Rectangle}">
                                        <Setter Property="OpacityMask" Value="{StaticResource VisualControlPlay}" />
                                        <Setter Property="Fill" Value="{DynamicResource GrayBrush3}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsTraceRunning}" Value="True">
                                                <Setter Property="OpacityMask" Value="{StaticResource VisualClose}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Rectangle.Style>
                            </Rectangle>
                            <TextBlock Grid.Column="1" FontSize="14" Margin="10,5" TextAlignment="Center">
                                <TextBlock.Style>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="Text" Value="{DynamicResource String_Button_Trace}"/>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsTraceRunning}" Value="True" >
                                                <Setter Property="Text" Value="{DynamicResource String_Button_Cancel}"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                        </Grid>
                    </Button.Content>
                </Button>
            </Grid>
            <Controls:MetroProgressBar Grid.Row="1" Margin="0,10,0,0" Foreground="{DynamicResource AccentColorBrush}" Visibility="{Binding IsTraceRunning, Converter={StaticResource BooleanToVisibilityConverter}}" IsIndeterminate="True" />
            <TextBlock Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding StatusMessage}" Visibility="{Binding DisplayStatusMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
        </Grid>
        <TextBlock Grid.Row="2" Text="{DynamicResource String_Header_Route}" Style="{StaticResource HeaderTextBlock}" />
        <DataGrid Grid.Row="3" ItemsSource="{Binding TraceResultView}" SelectedItem="{Binding SelectedTraceResult}" CanUserSortColumns="False">
            <DataGrid.Resources>
                <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource DataGridScrollBar}" />
                <WpfHelper:BindingProxy x:Key="BindingProxy" Data="{Binding}" />
                <ContextMenu x:Key="RowContextMenu" Opened="ContextMenu_Opened" MinWidth="150">
                    <MenuItem Header="{DynamicResource String_IPScanner}" Command="{Binding PerformIPScannerCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=Sitemap}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="{DynamicResource String_PortScanner}" Command="{Binding PerformPortScanCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Modern Kind=NetworkPort}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="{DynamicResource String_Ping}" Command="{Binding PerformPingCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=LanConnect}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>                  
                    <MenuItem Header="{DynamicResource String_DNSLookupDots}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=SearchWeb}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                        <MenuItem Header="{DynamicResource String_IPAddress}" Command="{Binding PerformDNSLookupIPAddressCommand}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=SearchWeb}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_Hostname}" Command="{Binding PerformDNSLookupHostnameCommand}" IsEnabled="{Binding SelectedTraceResult.Hostname, Converter={StaticResource StringIsNotNullOrEmptyToBoolConverter}}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=SearchWeb}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                    </MenuItem>
                    <MenuItem Header="{DynamicResource String_RemoteDesktop}" Command="{Binding ConnectRemoteDesktopCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=RemoteDesktop}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="{DynamicResource String_PuTTY}" Command="{Binding ConnectPuTTYCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Octicons Kind=Terminal}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="{DynamicResource String_SNMP}" Command="{Binding PerformSNMPCommand}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=Switch}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator />
                    <MenuItem Header="{DynamicResource String_CopyDots}">
                        <MenuItem.Icon>
                            <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                <Rectangle.OpacityMask>
                                    <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </MenuItem.Icon>
                        <MenuItem Header="{DynamicResource String_Hop}" Command="{Binding CopySelectedHopCommand}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_Time1}" Command="{Binding CopySelectedTime1Command}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_Time2}" Command="{Binding CopySelectedTime2Command}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_Time3}" Command="{Binding CopySelectedTime3Command}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_IPAddress}" Command="{Binding CopySelectedIPAddressCommand}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{DynamicResource String_Hostname}" Command="{Binding CopySelectedHostnameCommand}" Visibility="{Binding ValidatesOnDataErrors.ResolveHostname, Source={StaticResource BindingProxy}, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <MenuItem.Icon>
                                <Rectangle Width="16" Height="16" Fill="{DynamicResource BlackColorBrush}">
                                    <Rectangle.OpacityMask>
                                        <VisualBrush Stretch="Uniform" Visual="{IconPacks:Material Kind=ContentCopy}" />
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </MenuItem.Icon>
                        </MenuItem>
                    </MenuItem>
                </ContextMenu>
            </DataGrid.Resources>
            <DataGrid.RowStyle>
                <Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MetroDataGridRow}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectedItems.Count, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type DataGrid}}}" Value="1" >
                            <Setter Property="ContextMenu" Value="{StaticResource RowContextMenu}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Header="{DynamicResource String_Hop}" Binding="{Binding Hop}" MinWidth="80" />
                <DataGridTextColumn Header="{DynamicResource String_Time1}" MinWidth="100">
                    <DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource PingTimeToStringConverter}">
                            <Binding Path="Status1" />
                            <Binding Path="Time1" />
                        </MultiBinding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
                <DataGridTextColumn Header="{DynamicResource String_Time2}" MinWidth="100">
                    <DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource PingTimeToStringConverter}">
                            <Binding Path="Status2" />
                            <Binding Path="Time2" />
                        </MultiBinding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
                <DataGridTextColumn Header="{DynamicResource String_Time3}" MinWidth="100">
                    <DataGridTextColumn.Binding>
                        <MultiBinding Converter="{StaticResource PingTimeToStringConverter}">
                            <Binding Path="Status3" />
                            <Binding Path="Time3" />
                        </MultiBinding>
                    </DataGridTextColumn.Binding>
                </DataGridTextColumn>
                <DataGridTextColumn Header="{DynamicResource String_IPAddress}" Binding="{Binding IPAddress, Converter={StaticResource IPAddressToStringConverter}}" MinWidth="150" />
                <DataGridTextColumn Header="{DynamicResource String_Hostname}" Binding="{Binding Hostname}" Visibility="{Binding Data.ResolveHostname, Source={StaticResource BindingProxy}, Converter={StaticResource BooleanToVisibilityConverter}}" MinWidth="150" Width="*" />
            </DataGrid.Columns>
        </DataGrid>
        <Expander Grid.Row="4" IsExpanded="{Binding ExpandStatistics}" Visibility="{Binding ShowStatistics, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource HeaderExpander}" Margin="0,20,0,0">
            <Expander.Header>
                <TextBlock Text="{DynamicResource String_Header_Statistics}" Style="{StaticResource HeaderTextBlock}" Margin="0" />
            </Expander.Header>
            <StackPanel>
                <Grid Margin="0,10,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.Resources>
                        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
                        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockAsTextBox}">
                            <Setter Property="VerticalAlignment" Value="Center" />
                            <Setter Property="ContextMenu" Value="{StaticResource CopyContextMenu}" />
                            <Setter Property="TextWrapping" Value="NoWrap" />
                        </Style>
                    </Grid.Resources>
                    <TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_StartTime}" />
                    <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding StartTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="{DynamicResource String_Duration}" />
                    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Duration, StringFormat={}{0:hh}h {0:mm}m {0:ss}s {0:ff}ms}" />
                    <TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_EndTime}" />
                    <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding EndTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
                    <TextBlock Grid.Column="3" Grid.Row="0" Text="{DynamicResource String_Hops}" />
                    <TextBox Grid.Column="4" Grid.Row="0" Text="{Binding Hops}" />
                </Grid>
            </StackPanel>
        </Expander>
    </Grid>
</UserControl>
