-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLoginPage.xaml.cs
More file actions
46 lines (39 loc) · 1.63 KB
/
LoginPage.xaml.cs
File metadata and controls
46 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
namespace ReactiveUI.Samples.Maui;
/// <summary>
/// A reactive login page demonstrating WhenActivated, Bind, BindCommand,
/// and DisplayAlert for user feedback in MAUI.
/// </summary>
public partial class LoginPage : ReactiveUI.Maui.ReactiveContentPage<LoginViewModel>
{
/// <summary>
/// Initializes a new instance of the <see cref="LoginPage"/> class.
/// </summary>
public LoginPage()
{
InitializeComponent();
ViewModel = new LoginViewModel(RxSchedulers.MainThreadScheduler);
this.WhenActivated(d =>
{
this.Bind(ViewModel, vm => vm.UserName, v => v.Username.Text)
.DisposeWith(d);
this.Bind(ViewModel, vm => vm.Password, v => v.Password.Text)
.DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.Login, v => v.LoginButton)
.DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.Cancel, v => v.CancelButton)
.DisposeWith(d);
ViewModel.Login
.SelectMany(success => Observable.FromAsync(() =>
DisplayAlert(
success ? "Login Successful" : "Login Failed",
success ? "Welcome!" : "Invalid credentials.",
"OK")))
.Subscribe()
.DisposeWith(d);
});
}
}