Dispenser/DispenserUI/Views/Login/LoginView.axaml.cs

33 lines
1.0 KiB
C#

using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using DispenserCommon.Utils;
using DispenserUI.ViewModels.Login;
namespace DispenserUI.Views.Login;
public partial class LoginView : UserControl
{
private readonly TextBox? _pwdTextBox;
public LoginView()
{
DataContext = ViewModel;
InitializeComponent();
_pwdTextBox = this.FindControl<TextBox>("PwdTextBox");
//订阅大写键抬起事件、pwdTextBox焦点获得事件、pwdTextBox焦点丢失事件
KeyUp += async (sender, e) => await ViewModel.CapsLockUpCommand.Execute();
if (_pwdTextBox != null)
{
_pwdTextBox.GotFocus += async (sender, e) => await ViewModel.PwdTextBoxGotFocusCommand.Execute();
_pwdTextBox.LostFocus += async (sender, e) => await ViewModel.PwdTextBoxLostFocusCommand.Execute();
}
}
public LoginVM ViewModel { get; } = ServiceLocator.GetService<LoginVM>();
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}