<UserControl x:Class="NETworkManager.Views.CredentialsSetMasterPasswordDialog"
             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:WpfHelper="clr-namespace:NETworkManager.WpfHelper"
             xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" Loaded="UserControl_Loaded">
    <Grid Margin="0,20">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="10" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.Resources>
                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
                <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}" />
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>            
            <TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_Password}" />
            <PasswordBox x:Name="passwordBoxPassword" Grid.Column="2" Grid.Row="0" Style="{StaticResource DefaultPasswordBox}" >
                <Interactivity:Interaction.Behaviors>
                    <WpfHelper:PasswordBoxBindingBehavior Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </Interactivity:Interaction.Behaviors>
            </PasswordBox>
            <TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_Repeat}" />
            <PasswordBox x:Name="passwordBoxRepeat" Grid.Column="2" Grid.Row="2" Style="{StaticResource DefaultPasswordBox}">
                <Interactivity:Interaction.Behaviors>
                    <WpfHelper:PasswordBoxBindingBehavior Password="{Binding PasswordRepeat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </Interactivity:Interaction.Behaviors>
            </PasswordBox>
        </Grid>
        <TextBlock Grid.Row="1" Foreground="{DynamicResource AccentColorBrush}" Text="{DynamicResource String_PasswordsDoesNotMatch}" Margin="0,10,0,0">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlock}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding PasswordIsEmpty}" Value="False" />
                                <Condition Binding="{Binding PasswordsMatch}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter Property="Visibility" Value="Visible" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="{DynamicResource String_Button_Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
            <Button Content="{DynamicResource String_Button_Save}" Command="{Binding SaveCommand}" IsDefault="True" Margin="10,0,0,0">
                <Button.Style>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
                        <Setter Property="IsEnabled" Value="False" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding PasswordIsEmpty}" Value="False" />
                                    <Condition Binding="{Binding PasswordsMatch}" Value="True" />
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="IsEnabled" Value="True" />
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>
