test: 测试 MVVM 模式与绑定
This commit is contained in:
29
TestMvvm/ViewModels/MainWindowViewModel.cs
Normal file
29
TestMvvm/ViewModels/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace TestMvvm.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] public string? test = Path.GetRandomFileName();
|
||||
|
||||
[RelayCommand]
|
||||
public void RandomText()
|
||||
{
|
||||
Test = Path.GetRandomFileName();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ChangeToChinese()
|
||||
{
|
||||
App.I18NManager.Culture = new CultureInfo("zh-hans");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ChangeToDefault()
|
||||
{
|
||||
App.I18NManager.Culture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user