Hello,
i am trying to have one entry for an User object. the properties of the user could be changed so i need to pass the user then need to also keep it up-to-date in the different views.
What i did currently :
in App.xalm.cs
In my Login Page i put a listener in order to have all my current user properties changes.
Then put affect it to my App.LoggedUser
LoginPageViewModel.cs
For the other viewmodels,
like below, i created an User object to receive the App.loggedUser
HomePageViewModel
Any advices to do it in a proper way please. i am just a beginner try to do his first app with Firebase+Maui.net.
Is there a way to bind views directly with the App.LoggedUser ?
i am trying to have one entry for an User object. the properties of the user could be changed so i need to pass the user then need to also keep it up-to-date in the different views.
What i did currently :
in App.xalm.cs
C#:
public static Model.User LoggedUser = new();
In my Login Page i put a listener in order to have all my current user properties changes.
Then put affect it to my App.LoggedUser
LoginPageViewModel.cs
C#:
DocumentReference docRef = App.FirestoreDB.Collection("User").Document(userinfo.Info.Uid);
FirestoreChangeListener MyUserListener = docRef.Listen(snapshot =>
{
if (snapshot.Exists)
{
App.LoggedUser = (User)snapshot.ConvertTo<User>();
}
});
For the other viewmodels,
like below, i created an User object to receive the App.loggedUser
HomePageViewModel
C#:
public partial class HomePageViewModel : BaseViewModel
{
[ObservableProperty]
Model.User user;
public HomePageViewModel()
{
this.user = App.LoggedUser;
}
private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
User = App.LoggedUser;
}
}
Is there a way to bind views directly with the App.LoggedUser ?
Last edited by a moderator: