123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace Venus_MainPages.ViewModels
- {
- internal class TopViewModel : BindableBase
- {
- #region 私有字段
- private string m_Title;
- private string m_SoftwareVersion;
- #endregion
- #region 属性
- public string Title
- {
- get { return m_Title; }
- set { SetProperty(ref m_Title, value); }
- }
- public string SoftwareVersion
- {
- get { return m_SoftwareVersion; }
- set { SetProperty(ref m_SoftwareVersion, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand _SwichLanguageCommand;
- public DelegateCommand SwichLanguageCommand =>
- _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
- #endregion
- #region 构造函数
- public TopViewModel()
- {
- Title = "Venus";
- m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- }
- #endregion
- #region 方法
- private void OnSwitchLanguage()
- {
-
- List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
- foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
- {
- if (dictionary.Source != null)
- {
- dictionaryList.Add(dictionary);
- }
- }
- string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
- string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
- ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
- ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
- if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
- {
- Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
- Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
- }
- else
- {
- Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
- Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
- }
- }
- #endregion
- }
- }
|