Notes/Notes.Data/ViewModels/AboutViewModel.cs

107 lines
2.4 KiB
C#

using System;
using System.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
namespace Notes.ViewModels;
public partial class AboutViewModel:ViewModelBase
{
private readonly IServices _services;
public string Title => AppInfo.Name;
public string Version => AppInfo.VersionString;
public string Message => "This app is written in XAML and C# with Avalonia UI";
[RelayCommand]
public void ShowAllNotes()
{
_services.GetSafeAs<MainViewModel>().Navitation<AllNotesViewModel>();
}
[Obsolete("Used by designer",true)]
#pragma warning disable CS8618
public AboutViewModel()
#pragma warning restore CS8618
{
}
public AboutViewModel(IServices services)
{
this._services = services;
}
}
internal class AppInfo
{
public static string Name = "Cal Note";
public static string VersionString = "1.0.0";
}
public class ViewModel1 : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged(string propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
#region SavedValue Property
private string? _savedValue;
public string? SavedValue
{
get
{
return this._savedValue;
}
private set
{
if (this._savedValue == value)
{
return;
}
this._savedValue = value;
this.OnPropertyChanged(nameof(SavedValue));
this.OnPropertyChanged(nameof(CanSave));
}
}
#endregion SavedValue Property
#region NewValue Property
private string? _newValue;
public string? NewValue
{
get
{
return this._newValue;
}
set
{
if (this._newValue == value)
{
return;
}
this._newValue = value;
this.OnPropertyChanged(nameof(NewValue));
this.OnPropertyChanged(nameof(CanSave));
}
}
#endregion NewValue Property
// CanSave is set to true when SavedValue is not the same as NewView
// false otherwise
public bool CanSave => NewValue != SavedValue;
public void Save()
{
SavedValue = NewValue;
}
public void Cancel()
{
NewValue = SavedValue;
}
}