59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using AppClientBase.Services;
|
|
|
|
namespace AppClientBase.ViewModels;
|
|
|
|
/// <summary>
|
|
/// EN: Base ViewModel class with common functionality.
|
|
/// VI: Lớp ViewModel cơ sở với chức năng chung.
|
|
/// </summary>
|
|
public abstract partial class BaseViewModel : ObservableObject
|
|
{
|
|
/// <summary>
|
|
/// EN: Navigation service instance.
|
|
/// VI: Instance của dịch vụ điều hướng.
|
|
/// </summary>
|
|
protected readonly INavigationService NavigationService;
|
|
|
|
/// <summary>
|
|
/// EN: Indicates if the ViewModel is currently loading data.
|
|
/// VI: Cho biết ViewModel đang tải dữ liệu hay không.
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(IsNotBusy))]
|
|
private bool _isBusy;
|
|
|
|
/// <summary>
|
|
/// EN: Title of the current page.
|
|
/// VI: Tiêu đề của trang hiện tại.
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
private string _title = string.Empty;
|
|
|
|
/// <summary>
|
|
/// EN: Indicates if the ViewModel is not busy.
|
|
/// VI: Cho biết ViewModel không bận.
|
|
/// </summary>
|
|
public bool IsNotBusy => !IsBusy;
|
|
|
|
/// <summary>
|
|
/// EN: Constructor with navigation service.
|
|
/// VI: Constructor với dịch vụ điều hướng.
|
|
/// </summary>
|
|
protected BaseViewModel(INavigationService navigationService)
|
|
{
|
|
NavigationService = navigationService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// EN: Navigate back to previous page.
|
|
/// VI: Điều hướng quay lại trang trước.
|
|
/// </summary>
|
|
[RelayCommand]
|
|
protected virtual async Task GoBackAsync()
|
|
{
|
|
await NavigationService.GoBackAsync();
|
|
}
|
|
}
|