Can't navigate windows
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I try to make a login page which users will users use username and password to see Mainwindow.xaml that generated by WPF UI Template. Here is my code ;
This is the Login.xaml.cs
` public partial class Login
{
private MainWindowViewModel viewModel;
private PageService pageService;
private NavigationService navigationService;
private readonly AuthenticationService _authService;
public LoginViewModel ViewModel { get; }
public Login()
{
InitializeComponent();
_authService = new AuthenticationService(); // AuthenticationService örneği
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
string username = UsernameText.Text; // Kullanıcı adı TextBox'ı
string password = PasswordText.Password; // Şifre PasswordBox'ı
if (_authService.Authenticate(username, password))
{
System.Windows.MessageBox.Show("Giriş başarılı!", "Bilgi", System.Windows.MessageBoxButton.OK, MessageBoxImage.Information);
DialogResult = true; // Login başarılı -> Giriş ekranını kapat
Close();
}
else
{
System.Windows.MessageBox.Show("Kullanıcı adı veya şifre hatalı.", "Hata", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}`
That's the AuthenticationService.cs
`public class AuthenticationService
{
private readonly Dictionary<string, string> _users;
public AuthenticationService()
{
// Örnek kullanıcılar: Kullanıcı adı ve şifre çiftleri
_users = new Dictionary<string, string>
{
{ "admin", "12345" }, // Kullanıcı adı: admin, Şifre: 12345
{ "user1", "password" }
};
}
/// <summary>
/// Kullanıcı adı ve şifre doğrulaması yapar.
/// </summary>
/// <param name="username">Kullanıcı adı</param>
/// <param name="password">Şifre</param>
/// <returns>Doğrulama sonucu (true/false)</returns>
public bool Authenticate(string username, string password)
{
return _users.TryGetValue(username, out var storedPassword) && storedPassword == password;
}
}`
ApplicationHostService ;
` private async Task HandleActivationAsync()
{
// Login.xaml'i başlangıç ekranı olarak göster
if (!Application.Current.Windows.OfType().Any())
{
var loginWindow = new Login();
bool? loginResult = loginWindow.ShowDialog(); // Giriş ekranını modal olarak göster
if (loginResult != true || !UserIsAuthenticated())
{
// Kullanıcı giriş yapmadıysa uygulamayı kapat
Application.Current.Shutdown();
return;
}
}
// Kullanıcı doğrulandıysa MainWindow'u başlat
if (!Application.Current.Windows.OfType<MainWindow>().Any())
{
_navigationWindow = (
_serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow
)!;
_navigationWindow!.ShowWindow();
_navigationWindow.Navigate(typeof(Premium.Views.Pages.DashboardPage));
}
await Task.CompletedTask;
}`
To Reproduce
...
Expected behavior
If user credentials are true I want to switch to mainwindow
Screenshots
OS version
Windows 10
.NET version
.NET 8.0
WPF-UI NuGet version
3.0.5
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Login.xaml.cs, AuthenticationService.cs, and ApplicationHostService.HandleActivationAsync. Read how ShowDialog, ShowWindow, and the authentication check interact, then reproduce the login flow on Windows 10 with .NET 8 and WPF UI 3.0.5. Done means valid credentials reliably lead to the main window without prematurely shutting down the application.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- authentication, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100