Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't navigate windows #1300

Open
berkespace opened this issue Dec 27, 2024 · 0 comments
Open

Can't navigate windows #1300

berkespace opened this issue Dec 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@berkespace
Copy link

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

image

OS version

Windows 10

.NET version

.NET 8.0

WPF-UI NuGet version

3.0.5

Additional context

No response

@berkespace berkespace added the bug Something isn't working label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant