.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,114 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
For some reason my app breaks, when I add the loginViewModel to the mainPage
I am using firebase, so I register the user, and navigate to the Main Page
builder.Services.AddTransient<RegisterPopUp>();
builder.Services.AddSingleton<AppShell>();
builder.Services.AddTransient<MainViewModel>();
builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<LoginPage>();
builder.Services.AddTransient<LoginPageViewModel>();
Login page
public partial class LoginPageViewModel : BaseViewModel {
public required Action openPopUp;
public required Action closePopUp;
private FirebaseAuthClient _authClient;
public LoginPageViewModel(FirebaseAuthClient authClient) {
_authClient = authClient;
if(authClient.User != null) {
Shell.Current.GoToAsync($"{nameof(MainPage)}");
}
}
[ObservableProperty]
LocalUser _localUser = new();
[RelayCommand]
async Task Login() {
await _authClient.SignInWithEmailAndPasswordAsync(LocalUser.Email, LocalUser.Password);
await Shell.Current.GoToAsync($"{nameof(MainPage)}");
}
[RelayCommand]
async Task Register() {
openPopUp.Invoke();
}
// Popup Commands
[RelayCommand]
void ClosePopUp() {
closePopUp.Invoke();
}
[RelayCommand]
async Task SignUp() {
await _authClient.CreateUserWithEmailAndPasswordAsync(
LocalUser.Email,
LocalUser.Password,
LocalUser.Username);
closePopUp.Invoke();
await Shell.Current.GoToAsync($"{nameof(MainPage)}");
}
readonly RegisterPopUp _registerPopUp;
public LoginPage(LoginPageViewModel loginPageViewModel, RegisterPopUp registerPopUp) {
InitializeComponent();
BindingContext = loginPageViewModel;
_registerPopUp = registerPopUp;
loginPageViewModel.openPopUp = () => {
_registerPopUp.IsOpen = true;
};
loginPageViewModel.closePopUp = () => {
_registerPopUp.IsOpen = false;
};
}
AppShell
public partial class AppShell : Shell {
public AppShell() {
InitializeComponent();
Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
}
}
so
I will show you what is going on
the app is in