<Window x:Class="CefFlashBrowser.Views.Dialogs.SelectLanguageDialog"
        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:CefFlashBrowser.Views.Dialogs"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:behaviors="clr-namespace:CefFlashBrowser.Views.Behaviors"
        mc:Ignorable="d"
        
        Width="300"
        Height="300"
        ResizeMode="NoResize"
        WindowStartupLocation="CenterScreen"
        FocusManager.FocusedElement="{Binding ElementName=langList}"
        DataContext="{Binding Source={StaticResource Locator}, Path=LanguageSelectorViewModel}">

    <Window.InputBindings>
        <KeyBinding Gesture="Ctrl+W"
                    Command="{Binding ElementName=windowBehavior, Path=CloseWindowCommand}"/>
        <KeyBinding Gesture="Esc"
                    Command="{Binding ElementName=windowBehavior, Path=CloseWindowCommand}"/>
    </Window.InputBindings>

    <i:Interaction.Behaviors>
        <behaviors:WindowBehavior x:Name="windowBehavior"/>
    </i:Interaction.Behaviors>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <TextBlock Margin="15"
                       FontSize="20"
                       TextWrapping="Wrap"
                       HorizontalAlignment="Center"
                       Text="{DynamicResource dialog_selectLanguage}"
                       Foreground="{DynamicResource PrimaryTextBrush}"/>
        </Grid>
        <Grid Grid.Row="1">
            <ListBox x:Name="langList"
                     Margin="15,0"
                     ItemsSource="{Binding LanguageList}"
                     DisplayMemberPath="LanguageName"
                     SelectedValuePath="Language">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem"
                           BasedOn="{StaticResource ListBoxItemBaseStyle}">
                        <Setter Property="IsSelected"
                                Value="{Binding IsCurrentLanguage, Mode=OneWay}"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding SetLanguageCommand}"
                                               CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=SelectedValue}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListBox>
        </Grid>
        <Grid Grid.Row="2">
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Right">
                <Button Margin="15"
                        MinWidth="70"
                        Style="{StaticResource ButtonPrimary}"
                        Content="{DynamicResource dialog_ok}"
                        Click="OnConfirmButtonClick"/>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
