58 <sys:String x:Key="Looking">Looking at mountains is not mountains, looking at water is not water, looking at mountains is still mountains, looking at water is still water</sys:String>
60 <sys:String x:Key="DialogBoxAnnouncement">This is a WPF version of the Layui component library, where you can feel the charm of the WPF version of Layui</sys:String>
61 <sys:String x:Key="ModalPopUpWindow">This is a modal pop-up window</sys:String>
62 <sys:String x:Key="NonModalPopUpWindow">This is a non modal pop-up window</sys:String>
63 </ResourceDictionary>
复制代码
View Code
4.编写MainWindowViewModel,实现主窗体属性和命令的绑定
1 /// <summary>
2 /// 多语言
3 /// </summary>
4 public class Language : BindableBase
5 {
6 private string _Title;
7 public string Title
8 {
9 get { return _Title; }
10 set { SetProperty(ref _Title, value); }
11 }
12 private string _Icon;
13 public string Icon
14 {
15 get { return _Icon; }
16 set { SetProperty(ref _Icon, value); }
17 }
18 private string _Key;
19 public string Key
20 {
21 get { return _Key; }
22 set { SetProperty(ref _Key, value); }
23 }
24 }
25
26 /// <summary>
27 /// 主窗口ViewModel
28 /// </summary>
29 public class MainWindowViewModel : ViewModelBase
30 {
31 private Language _Language;
32 public Language Language
33 {
34 get { return _Language; }
35 set
36 {
37 SetProperty(ref _Language, value);
38 language.LoadResourceKey(Language.Key);
39 }
40 }
41
42 private List<Language> _Languages = new List<Language>()
43 {
44 new Language(){ Title="中文",Icon="Images/Svg/cn.svg",Key="zh_CN" },
45 new Language(){ Title="英语",Icon="Images/Svg/um.svg",Key="en_US" },
46 };
47 public List<Language> Languages
48 {
49 get { return _Languages; }
50 set { SetProperty(ref _Languages, value); }
51 }
52
53 private string _Message = "";
54 public string Message
55 {
56 get { return _Message; }
57 set { SetProperty(ref _Message, value); }
58 }
59 public MainWindowViewModel(IContainerExtension container) : base(container)
60 {
61 Language = Languages.FirstOrDefault();
62 }
63 #region 视图属性
64 private bool _Network = true;
65 public bool Network
66 {
67 get { return _Network; }
68 set { SetProperty(ref _Network, value); }
69 }
70
71 /// <summary>
72 /// 标题
73 /// </summary>
74 private string _title = nameof(Title);
75 public string Title
76 {
77 get { return _title; }
78 set { SetProperty(ref _title, value); }
79 }
80
81 /// <summary>
82 /// 窗体状态
83 /// </summary>
84 private WindowState _WindowState;
85 public WindowState WindowState
86 {
87 get { return _WindowState; }
88 set { _WindowState = value; RaisePropertyChanged(); }
89 }
90
91 /// <summary>
92 ///
93 /// </summary>
94 private Thickness _GlassFrameThickness;
95 public Thickness GlassFrameThickness
96 {
97 get { return _GlassFrameThickness; }
98 set { _GlassFrameThickness = value; RaisePropertyChanged(); }