Skip to content

Commit

Permalink
Fix #21 - Authentication UI wasn't getting proper focus. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
veler authored Aug 23, 2020
1 parent 03bb6b0 commit 1cbdfbd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Windows/Impl/PaZword/Views/Other/AuthenticationPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
</StackPanel>
<StackPanel
x:Name="RetryWindowsHelloStackPanel"
TabFocusNavigation="Cycle"
Visibility="{x:Bind ViewModel.IsWindowsHelloAuthenticationInProgress, Converter={StaticResource InvertedBooleanToVisibilityConverter}, Mode=OneWay}">
<TextBlock
Expand All @@ -65,6 +66,7 @@
VerticalAlignment="Center"/>
<Button
x:Name="RetryWindowsHelloAuthenticationButton"
TabIndex="0"
Margin="0,10,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Expand All @@ -76,6 +78,7 @@

<!-- Two Factor Authentication -->
<Grid
x:Name="TwoFactorAuthenticationGrid"
Visibility="{x:Bind ViewModel.AuthenticationStep, ConverterParameter='TwoFactorAuthentication', Converter={StaticResource EnumToVisibilityConverter}, Mode=OneWay}">
<StackPanel
TabFocusNavigation="Cycle"
Expand All @@ -90,17 +93,21 @@
HorizontalAlignment="Center"
TextTrimming="CharacterEllipsis"/>
<TextBox
x:Name="TwoFactorAuthenticationTextBox"
TabIndex="0"
Margin="0,10,0,0"
PlaceholderText="{x:Bind ViewModel.Strings.CodeGenerated}"
Text="{x:Bind ViewModel.TwoFactorVerificationCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<HyperlinkButton
TabIndex="1"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
Content="{x:Bind ViewModel.Strings.TwoFactorUseEmail}"
IsEnabled="{x:Bind ViewModel.IsInternetAccess}"
HorizontalAlignment="Center"
Command="{x:Bind ViewModel.SendRecoveryKeyByEmailCommand}"/>
</StackPanel>
<StackPanel
x:Name="TwoFactorAuthenticationEmailAddressStackPanel"
TabFocusNavigation="Cycle"
Visibility="{x:Bind ViewModel.IsTwoFactorAuthenticationByEmailInProgress, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
<FontIcon
Expand All @@ -120,6 +127,8 @@
TextWrapping="WrapWholeWords"
TextTrimming="CharacterEllipsis"/>
<TextBox
x:Name="TwoFactorAuthenticationEmailAddressTextBox"
TabIndex="0"
Margin="0,10,0,0"
PlaceholderText="{x:Bind ViewModel.Strings.CodeGeneratedEmail}"
Text="{x:Bind ViewModel.TwoFactorVerificationCodeEmail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Expand All @@ -128,6 +137,7 @@

<!-- Recovery Key -->
<StackPanel
x:Name="RecoveryKeyStackPanel"
TabFocusNavigation="Cycle"
Visibility="{x:Bind ViewModel.AuthenticationStep, ConverterParameter='RecoveryKey', Converter={StaticResource EnumToVisibilityConverter}, Mode=OneWay}">
<FontIcon
Expand All @@ -147,6 +157,8 @@
TextWrapping="WrapWholeWords"
TextTrimming="CharacterEllipsis"/>
<TextBox
x:Name="RecoveryKeyTextBox"
TabIndex="0"
Margin="0,10,0,0"
PlaceholderText="{x:Bind ViewModel.Strings.EnterSecretKeyTextBox}"
Text="{x:Bind ViewModel.RecoveryKey, Converter={StaticResource SecureStringToStringConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
Expand Down
44 changes: 44 additions & 0 deletions Windows/Impl/PaZword/Views/Other/AuthenticationPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using PaZword.ViewModels.Other;
using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace PaZword.Views.Other
Expand All @@ -21,6 +26,45 @@ public AuthenticationPage()
InitializeComponent();

ViewModel.Initialize();

RecoveryKeyStackPanel.RegisterPropertyChangedCallback(UIElement.VisibilityProperty, VisibilityChanged);
RetryWindowsHelloStackPanel.RegisterPropertyChangedCallback(UIElement.VisibilityProperty, VisibilityChanged);
TwoFactorAuthenticationEmailAddressStackPanel.RegisterPropertyChangedCallback(UIElement.VisibilityProperty, VisibilityChanged);
TwoFactorAuthenticationGrid.RegisterPropertyChangedCallback(UIElement.VisibilityProperty, VisibilityChanged);
}

private void VisibilityChanged(DependencyObject sender, DependencyProperty dp)
{
if (sender is Panel control
&& control.Visibility == Visibility.Visible)
{
// Slightly delay setting focus
Task.Factory.StartNew(async () =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
if (control == RecoveryKeyStackPanel)
{
RecoveryKeyTextBox.Focus(FocusState.Keyboard);
}
else if (control == RetryWindowsHelloStackPanel)
{
RetryWindowsHelloAuthenticationButton.Focus(FocusState.Keyboard);
}
else if (control == TwoFactorAuthenticationGrid)
{
TwoFactorAuthenticationTextBox.Focus(FocusState.Keyboard);
}
else if (control == TwoFactorAuthenticationEmailAddressStackPanel)
{
TwoFactorAuthenticationEmailAddressTextBox.Focus(FocusState.Keyboard);
}
});
},
CancellationToken.None,
TaskCreationOptions.None,
TaskScheduler.Default);
}
}
}
}

0 comments on commit 1cbdfbd

Please sign in to comment.