Tastaturnavigation auf der Login-Seite hinzugefügt

This commit is contained in:
2026-02-25 10:35:23 +01:00
parent 95f71e34c7
commit 9207d5e8d6
2 changed files with 31 additions and 15 deletions

View File

@@ -2,7 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
Title="LogInPage"> Title="LogInPage"
KeyboardNavigation.DirectionalNavigation="Cycle"
Loaded="Page_Loaded">
<Grid Margin="40,20"> <Grid Margin="40,20">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -32,14 +34,14 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="Email (Benutzername):" Grid.Row="0" FontWeight="SemiBold"/> <Label Content="Email (Benutzername):" Grid.Row="0" FontWeight="SemiBold"/>
<TextBox x:Name="BenutzernameTextBox" Grid.Row="1" Height="45" FontSize="14"/> <TextBox x:Name="BenutzernameTextBox" Grid.Row="1" Height="45" FontSize="14" VerticalContentAlignment="Center" TabIndex="0" PreviewKeyDown="BenutzernameTextBox_PreviewKeyDown"/>
<Label Content="Passwort:" Grid.Row="3" FontWeight="SemiBold"/> <Label Content="Passwort:" Grid.Row="3" FontWeight="SemiBold"/>
<PasswordBox x:Name="PasswortTextBox" Grid.Row="4" Height="45" FontSize="14"/> <PasswordBox x:Name="PasswortTextBox" Grid.Row="4" Height="45" FontSize="14" VerticalContentAlignment="Center" TabIndex="1"/>
<StackPanel Grid.Row="6" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,0,0"> <StackPanel Grid.Row="6" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,0,0">
<Button Content="Login" Width="140" Height="48" Margin="0,0,20,0" Background="#FF1E88E5" Foreground="White" FontWeight="Bold" Click="LogInButton_Click"/> <Button Content="Login" Width="140" Height="48" Margin="0,0,20,0" Background="#FF1E88E5" Foreground="White" FontWeight="Bold" Click="LogInButton_Click" TabIndex="2" IsDefault="True"/>
<Button Content="Registrieren" Width="140" Height="48" Background="Transparent" BorderBrush="#DDD" Foreground="#666" Click="anmeldungsButton_Click"/> <Button Content="Registrieren" Width="140" Height="48" Background="Transparent" BorderBrush="#DDD" Foreground="#666" Click="anmeldungsButton_Click" TabIndex="3"/>
</StackPanel> </StackPanel>
<TextBlock Grid.Row="7" HorizontalAlignment="Center" Margin="0,20,0,0"> <TextBlock Grid.Row="7" HorizontalAlignment="Center" Margin="0,20,0,0">

View File

@@ -1,8 +1,9 @@
using System; using BCrypt.Net;
using MySql.Data.MySqlClient;
using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using MySql.Data.MySqlClient; using System.Windows.Input;
using BCrypt.Net;
namespace SkyTeam namespace SkyTeam
{ {
@@ -34,9 +35,9 @@ namespace SkyTeam
} }
string query = @" string query = @"
SELECT Id, Vorname, Rolle, PasswortHash SELECT Id, Vorname, Rolle, PasswortHash
FROM users FROM users
WHERE Email = @email"; WHERE Email = @email";
try try
{ {
@@ -64,14 +65,12 @@ namespace SkyTeam
return; return;
} }
SessionManager.CurrentUserId = reader.GetInt32("Id"); SessionManager.CurrentUserId = reader.GetInt32("Id");
SessionManager.CurrentUserName = reader.GetString("Vorname"); SessionManager.CurrentUserName = reader.GetString("Vorname");
SessionManager.Role = reader.GetString("Rolle"); SessionManager.Role = reader.GetString("Rolle");
} }
} }
((MainWindow)Application.Current.MainWindow) ((MainWindow)Application.Current.MainWindow)
.MainFrame.Navigate(new NavigationPage()); .MainFrame.Navigate(new NavigationPage());
} }
@@ -82,12 +81,27 @@ namespace SkyTeam
} }
} }
private void anmeldungsButton_Click(object sender, RoutedEventArgs e) private void anmeldungsButton_Click(object sender, RoutedEventArgs e)
{ {
((MainWindow)Application.Current.MainWindow) ((MainWindow)Application.Current.MainWindow)
.MainFrame.Navigate(new RegistrationPage()); .MainFrame.Navigate(new RegistrationPage());
} }
private void Page_Loaded(object sender, RoutedEventArgs e)
{
BenutzernameTextBox.Focus();
}
private void BenutzernameTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down || e.Key == Key.Enter)
{
TraversalRequest request =
new TraversalRequest(FocusNavigationDirection.Next);
(sender as UIElement).MoveFocus(request);
e.Handled = true;
}
}
} }
} }