private void HomeView_Loaded(object sender, RoutedEventArgs e) { MainWindow = (MainWindow)Window.GetWindow(this); MainViewModel = (MainViewModel)MainWindow.DataContext; MainWindow.Width = 1200; MainWindow.Height = 800; MainWindow.CenterWindowOnScreen(); Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { Request request = new Request { Type = RequestResponseType.FindCurrentUser, SessionToken = MainModel.SessionToken }; NetworkListener.SendRequest(request); })); ModelChangedHandler handler = null; handler = (string fieldName, Object field) => { if (fieldName == "User") { User user = MainModel.User; ((HomeViewModel)DataContext).DisplayName = $"{user.FirstName} {user.LastName} ({user.Username})"; } MainModel.ModelChanged -= handler; }; MainModel.ModelChanged += handler; }
private void Login(object sender, RoutedEventArgs e) { Request request = new Request { Type = RequestResponseType.Login, User = new User { Username = usernameOrEmail.Text, Email = usernameOrEmail.Text, Password = password.Password } }; ModelChangedHandler handler = null; handler = (string fieldName, Object field) => { if (fieldName == "SessionToken") { MainViewModel.CurrentView = new HomeView(); } MainModel.ModelChanged -= handler; }; MainModel.ModelChanged += handler; NetworkListener.SendRequest(request); }
private void EventView_Loaded(object sender, RoutedEventArgs e) { ModelChangedHandler handler = null; handler = (string fieldName, Object field) => { if (fieldName == "User") { User user = MainModel.User; if (user != null) { if (user.JoinedEvents != null) { foreach (Event @event in MainModel.User.JoinedEvents) { events.Children.Add(new EventCardView { DataContext = new EventCardViewModel { Title = @event.Title, Description = @event.Description } }); } } else { mainGrid.Children.Add(new Label { Content = "There are no events yet..." }); } } } }; MainModel.ModelChanged += handler; }