diff --git a/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs b/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs index 3b7d4966..cbade368 100644 --- a/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs +++ b/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs @@ -11,9 +11,9 @@ namespace HandyControlDemo.Resources public override ResourceDictionary GetSkin(SkinType skinType) => ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skinType); - public override ResourceDictionary GetTheme() => new Lazy(() => new ResourceDictionary + public override ResourceDictionary GetTheme() => new() { Source = new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml") - }).Value; + }; } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/ChatBoxViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/ChatBoxViewModel.cs index 3ad2e3cc..cd14d41e 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/ChatBoxViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/ChatBoxViewModel.cs @@ -24,7 +24,7 @@ namespace HandyControlDemo.ViewModel private readonly string _id = Guid.NewGuid().ToString(); - private readonly Stopwatch _stopwatch = new Lazy(() => new Stopwatch()).Value; + private readonly Stopwatch _stopwatch = new(); public ChatBoxViewModel() { @@ -52,8 +52,7 @@ namespace HandyControlDemo.ViewModel public ObservableCollection ChatInfos { get; set; } = new(); - public RelayCommand SendStringCmd => new Lazy>(() => - new RelayCommand(SendString)).Value; + public RelayCommand SendStringCmd => new(SendString); private void SendString(KeyEventArgs e) { @@ -73,12 +72,11 @@ namespace HandyControlDemo.ViewModel } } - public RelayCommand ReadMessageCmd => new Lazy>(() => - new RelayCommand(ReadMessage)).Value; + public RelayCommand ReadMessageCmd => new(ReadMessage); private void ReadMessage(RoutedEventArgs e) { - if (e.OriginalSource is FrameworkElement element && element.Tag is ChatInfoModel info) + if (e.OriginalSource is FrameworkElement {Tag: ChatInfoModel info}) { if (info.Type == ChatMessageType.Image) { @@ -95,8 +93,7 @@ namespace HandyControlDemo.ViewModel } } - public RelayCommand StartRecordCmd => new Lazy(() => - new RelayCommand(StartRecord)).Value; + public RelayCommand StartRecordCmd => new(StartRecord); private void StartRecord() { @@ -111,8 +108,7 @@ namespace HandyControlDemo.ViewModel _stopwatch.Start(); } - public RelayCommand StopRecordCmd => new Lazy(() => - new RelayCommand(StopRecord)).Value; + public RelayCommand StopRecordCmd => new(StopRecord); private void StopRecord() { @@ -149,8 +145,7 @@ namespace HandyControlDemo.ViewModel Messenger.Default.Send(info, MessageToken.SendChatMessage); } - public RelayCommand OpenImageCmd => new Lazy(() => - new RelayCommand(OpenImage)).Value; + public RelayCommand OpenImageCmd => new(OpenImage); private void OpenImage() { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs index 1c998867..ee4c3f14 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs @@ -33,6 +33,6 @@ namespace HandyControlDemo.ViewModel #endif } - public RelayCommand CloseCmd => new Lazy(() => new RelayCommand(() => CloseAction?.Invoke())).Value; + public RelayCommand CloseCmd => new(() => CloseAction?.Invoke()); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/BadgeDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/BadgeDemoViewModel.cs index 01dcbc71..d621cbef 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/BadgeDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/BadgeDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; namespace HandyControlDemo.ViewModel @@ -18,7 +17,6 @@ namespace HandyControlDemo.ViewModel #endif } - public RelayCommand CountCmd => new Lazy(() => - new RelayCommand(() => Count++)).Value; + public RelayCommand CountCmd => new(() => Count++); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/CardDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/CardDemoViewModel.cs index 9799eba8..d48468a3 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/CardDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/CardDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Command; using HandyControlDemo.Data; using HandyControlDemo.Service; @@ -15,16 +14,14 @@ namespace HandyControlDemo.ViewModel DataList = dataService.GetCardDataList(); } - public RelayCommand AddItemCmd => new Lazy(() => - new RelayCommand(() => DataList.Insert(0, _dataService.GetCardData()))).Value; + public RelayCommand AddItemCmd => new(() => DataList.Insert(0, _dataService.GetCardData())); - public RelayCommand RemoveItemCmd => new Lazy(() => - new RelayCommand(() => + public RelayCommand RemoveItemCmd => new(() => + { + if (DataList.Count > 0) { - if (DataList.Count > 0) - { - DataList.RemoveAt(0); - } - })).Value; + DataList.RemoveAt(0); + } + }); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs index 6d446137..7f9572c1 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs @@ -27,8 +27,7 @@ namespace HandyControlDemo.ViewModel #endif } - public RelayCommand ShowTextCmd => new Lazy>(() => - new RelayCommand(ShowText)).Value; + public RelayCommand ShowTextCmd => new(ShowText); private void ShowText(FrameworkElement element) { @@ -43,8 +42,7 @@ namespace HandyControlDemo.ViewModel } #if NET40 - public RelayCommand ShowInteractiveDialogCmd => new Lazy>(() => - new RelayCommand(ShowInteractiveDialog)).Value; + public RelayCommand ShowInteractiveDialogCmd => new(ShowInteractiveDialog); private void ShowInteractiveDialog(bool withTimer) { @@ -60,8 +58,7 @@ namespace HandyControlDemo.ViewModel } } #else - public RelayCommand ShowInteractiveDialogCmd => new Lazy>(() => - new RelayCommand(async withTimer => await ShowInteractiveDialog(withTimer))).Value; + public RelayCommand ShowInteractiveDialogCmd => new(async withTimer => await ShowInteractiveDialog(withTimer)); private async Task ShowInteractiveDialog(bool withTimer) { @@ -78,13 +75,11 @@ namespace HandyControlDemo.ViewModel } #endif - public RelayCommand NewWindowCmd => new Lazy(() => - new RelayCommand(() => new DialogDemoWindow - { - Owner = Application.Current.MainWindow - }.Show())).Value; + public RelayCommand NewWindowCmd => new(() => new DialogDemoWindow + { + Owner = Application.Current.MainWindow + }.Show()); - public RelayCommand ShowWithTokenCmd => new Lazy>(() => - new RelayCommand(token => Dialog.Show(new TextDialog(), token))).Value; + public RelayCommand ShowWithTokenCmd => new(token => Dialog.Show(new TextDialog(), token)); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/GrowlDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/GrowlDemoViewModel.cs index 90b6b967..af86c3d6 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/GrowlDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/GrowlDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Windows; +using System.Windows; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; using HandyControl.Data; @@ -23,94 +22,79 @@ namespace HandyControlDemo.ViewModel #region Window - public RelayCommand InfoCmd => new Lazy(() => - new RelayCommand(() => Growl.Info(Properties.Langs.Lang.GrowlInfo, _token))).Value; + public RelayCommand InfoCmd => new(() => Growl.Info(Properties.Langs.Lang.GrowlInfo, _token)); - public RelayCommand SuccessCmd => new Lazy(() => - new RelayCommand(() => Growl.Success(Properties.Langs.Lang.GrowlSuccess, _token))).Value; + public RelayCommand SuccessCmd => new(() => Growl.Success(Properties.Langs.Lang.GrowlSuccess, _token)); - public RelayCommand WarningCmd => new Lazy(() => - new RelayCommand(() => Growl.Warning(new GrowlInfo - { - Message = Properties.Langs.Lang.GrowlWarning, - CancelStr = Properties.Langs.Lang.Ignore, - ActionBeforeClose = isConfirmed => - { - Growl.Info(isConfirmed.ToString()); - return true; - }, - Token = _token - }))).Value; - - public RelayCommand ErrorCmd => new Lazy(() => - new RelayCommand(() => Growl.Error(Properties.Langs.Lang.GrowlError, _token))).Value; - - public RelayCommand AskCmd => new Lazy(() => - new RelayCommand(() => Growl.Ask(Properties.Langs.Lang.GrowlAsk, isConfirmed => + public RelayCommand WarningCmd => new(() => Growl.Warning(new GrowlInfo + { + Message = Properties.Langs.Lang.GrowlWarning, + CancelStr = Properties.Langs.Lang.Ignore, + ActionBeforeClose = isConfirmed => { Growl.Info(isConfirmed.ToString()); return true; - }, _token))).Value; + }, + Token = _token + })); - public RelayCommand FatalCmd => new Lazy(() => - new RelayCommand(() => Growl.Fatal(new GrowlInfo - { - Message = Properties.Langs.Lang.GrowlFatal, - ShowDateTime = false, - Token = _token - }))).Value; + public RelayCommand ErrorCmd => new(() => Growl.Error(Properties.Langs.Lang.GrowlError, _token)); - public RelayCommand ClearCmd => new Lazy(() => - new RelayCommand(() => Growl.Clear(_token))).Value; + public RelayCommand AskCmd => new(() => Growl.Ask(Properties.Langs.Lang.GrowlAsk, isConfirmed => + { + Growl.Info(isConfirmed.ToString()); + return true; + }, _token)); + + public RelayCommand FatalCmd => new(() => Growl.Fatal(new GrowlInfo + { + Message = Properties.Langs.Lang.GrowlFatal, + ShowDateTime = false, + Token = _token + })); + + public RelayCommand ClearCmd => new(() => Growl.Clear(_token)); #endregion #region Desktop - public RelayCommand InfoGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.InfoGlobal(Properties.Langs.Lang.GrowlInfo))).Value; + public RelayCommand InfoGlobalCmd => new(() => Growl.InfoGlobal(Properties.Langs.Lang.GrowlInfo)); - public RelayCommand SuccessGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.SuccessGlobal(Properties.Langs.Lang.GrowlSuccess))).Value; + public RelayCommand SuccessGlobalCmd => new(() => Growl.SuccessGlobal(Properties.Langs.Lang.GrowlSuccess)); - public RelayCommand WarningGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.WarningGlobal(new GrowlInfo - { - Message = Properties.Langs.Lang.GrowlWarning, - CancelStr = Properties.Langs.Lang.Ignore, - ActionBeforeClose = isConfirmed => - { - Growl.InfoGlobal(isConfirmed.ToString()); - return true; - } - }))).Value; - - public RelayCommand ErrorGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.ErrorGlobal(Properties.Langs.Lang.GrowlError))).Value; - - public RelayCommand AskGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.AskGlobal(Properties.Langs.Lang.GrowlAsk, isConfirmed => + public RelayCommand WarningGlobalCmd => new(() => Growl.WarningGlobal(new GrowlInfo + { + Message = Properties.Langs.Lang.GrowlWarning, + CancelStr = Properties.Langs.Lang.Ignore, + ActionBeforeClose = isConfirmed => { Growl.InfoGlobal(isConfirmed.ToString()); return true; - }))).Value; + } + })); - public RelayCommand FatalGlobalCmd => new Lazy(() => - new RelayCommand(() => Growl.FatalGlobal(new GrowlInfo - { - Message = Properties.Langs.Lang.GrowlFatal, - ShowDateTime = false - }))).Value; + public RelayCommand ErrorGlobalCmd => new(() => Growl.ErrorGlobal(Properties.Langs.Lang.GrowlError)); - public RelayCommand ClearGlobalCmd => new Lazy(() => - new RelayCommand(Growl.ClearGlobal)).Value; + public RelayCommand AskGlobalCmd => new(() => Growl.AskGlobal(Properties.Langs.Lang.GrowlAsk, isConfirmed => + { + Growl.InfoGlobal(isConfirmed.ToString()); + return true; + })); + + public RelayCommand FatalGlobalCmd => new(() => Growl.FatalGlobal(new GrowlInfo + { + Message = Properties.Langs.Lang.GrowlFatal, + ShowDateTime = false + })); + + public RelayCommand ClearGlobalCmd => new(Growl.ClearGlobal); #endregion - public RelayCommand NewWindowCmd => new Lazy(() => - new RelayCommand(() => new GrowlDemoWindow - { - Owner = Application.Current.MainWindow - }.Show())).Value; + public RelayCommand NewWindowCmd => new(() => new GrowlDemoWindow + { + Owner = Application.Current.MainWindow + }.Show()); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/ImageBrowserDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/ImageBrowserDemoViewModel.cs index eccaeeb9..4be859e6 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/ImageBrowserDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/ImageBrowserDemoViewModel.cs @@ -6,8 +6,7 @@ namespace HandyControlDemo.ViewModel { public class ImageBrowserDemoViewModel { - public RelayCommand OpenImgCmd => new Lazy(() => - new RelayCommand(() => - new ImageBrowser(new Uri("pack://application:,,,/Resources/Img/1.jpg")).Show())).Value; + public RelayCommand OpenImgCmd => new(() => + new ImageBrowser(new Uri("pack://application:,,,/Resources/Img/1.jpg")).Show()); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotificationDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotificationDemoViewModel.cs index 807bd4cc..be74cc4c 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotificationDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotificationDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; using HandyControl.Data; @@ -9,8 +8,7 @@ namespace HandyControlDemo.ViewModel { public class NotificationDemoViewModel : ViewModelBase { - public RelayCommand OpenCmd => new Lazy(() => - new RelayCommand(() => Notification.Show(new AppNotification(), ShowAnimation, StaysOpen))).Value; + public RelayCommand OpenCmd => new(() => Notification.Show(new AppNotification(), ShowAnimation, StaysOpen)); private ShowAnimation _showAnimation; diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotifyIconDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotifyIconDemoViewModel.cs index 1915f080..88e29879 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotifyIconDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/NotifyIconDemoViewModel.cs @@ -93,11 +93,9 @@ namespace HandyControlDemo.ViewModel #endif } - public RelayCommand MouseCmd => new Lazy>(() => - new RelayCommand(str => Growl.Info(str.ToString()))).Value; + public RelayCommand MouseCmd => new(str => Growl.Info(str.ToString())); - public RelayCommand SendNotificationCmd => new Lazy(() => - new RelayCommand(SendNotification)).Value; + public RelayCommand SendNotificationCmd => new(SendNotification); private void SendNotification() { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/PaginationDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/PaginationDemoViewModel.cs index 387e4621..f2d71b32 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/PaginationDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/PaginationDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using GalaSoft.MvvmLight.Command; using HandyControl.Data; @@ -42,9 +41,7 @@ namespace HandyControlDemo.ViewModel /// /// 页码改变命令 /// - public RelayCommand> PageUpdatedCmd => - new Lazy>>(() => - new RelayCommand>(PageUpdated)).Value; + public RelayCommand> PageUpdatedCmd => new(PageUpdated); /// /// 页码改变 diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SearchBarDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SearchBarDemoViewModel.cs index a2c12765..71b85433 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SearchBarDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SearchBarDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; @@ -7,8 +6,7 @@ namespace HandyControlDemo.ViewModel { public class SearchBarDemoViewModel : ViewModelBase { - public RelayCommand SearchCmd => new Lazy>(() => - new RelayCommand(Search)).Value; + public RelayCommand SearchCmd => new(Search); private void Search(string key) { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SideMenuDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SideMenuDemoViewModel.cs index 0190042f..461a2e66 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SideMenuDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SideMenuDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; using HandyControl.Data; @@ -8,13 +7,11 @@ namespace HandyControlDemo.ViewModel { public class SideMenuDemoViewModel : ViewModelBase { - public RelayCommand> SwitchItemCmd => new Lazy>>(() => - new RelayCommand>(SwitchItem)).Value; + public RelayCommand> SwitchItemCmd => new(SwitchItem); private void SwitchItem(FunctionEventArgs info) => Growl.Info((info.Info as SideMenuItem)?.Header.ToString()); - public RelayCommand SelectCmd => new Lazy>(() => - new RelayCommand(Select)).Value; + public RelayCommand SelectCmd => new(Select); private void Select(string header) => Growl.Success(header); } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SplitButtonDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SplitButtonDemoViewModel.cs index 0645b1c3..65ab3c8e 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SplitButtonDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SplitButtonDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; @@ -7,7 +6,6 @@ namespace HandyControlDemo.ViewModel { public class SplitButtonDemoViewModel : ViewModelBase { - public RelayCommand SelectCmd => new Lazy>(() => - new RelayCommand(str => Growl.Info(str))).Value; + public RelayCommand SelectCmd => new(str => Growl.Info(str)); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SpriteDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SpriteDemoViewModel.cs index 8ee307dd..9de153b2 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SpriteDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/SpriteDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Command; using HandyControl.Controls; using HandyControlDemo.UserControl; @@ -7,7 +6,6 @@ namespace HandyControlDemo.ViewModel { public class SpriteDemoViewModel { - public RelayCommand OpenCmd => new Lazy(() => - new RelayCommand(() => Sprite.Show(new AppSprite()))).Value; + public RelayCommand OpenCmd => new(() => Sprite.Show(new AppSprite())); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs index c5fbcd0c..41f4de2f 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Windows.Controls; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; @@ -27,12 +26,12 @@ namespace HandyControlDemo.ViewModel /// /// 下一步 /// - public RelayCommand NextCmd => new Lazy>(() => new RelayCommand(Next)).Value; + public RelayCommand NextCmd => new(Next); /// /// 上一步 /// - public RelayCommand PrevCmd => new Lazy>(() => new RelayCommand(Prev)).Value; + public RelayCommand PrevCmd => new(Prev); private void Next(Panel panel) { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs index 10fa00ed..7d4ea723 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TabControlDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Windows; +using System.Windows; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; using HandyControl.Data; @@ -12,16 +11,14 @@ namespace HandyControlDemo.ViewModel { public TabControlDemoViewModel(DataService dataService) => DataList = dataService.GetTabControlDemoDataList(); - public RelayCommand ClosingCmd => new Lazy>(() => - new RelayCommand(Closing)).Value; + public RelayCommand ClosingCmd => new(Closing); private void Closing(CancelRoutedEventArgs args) { Growl.Info($"{(args.OriginalSource as TabItem)?.Header} Closing"); } - public RelayCommand ClosedCmd => new Lazy>(() => - new RelayCommand(Closed)).Value; + public RelayCommand ClosedCmd => new(Closed); private void Closed(RoutedEventArgs args) { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs index be603164..b73eaae6 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/TagDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HandyControl.Controls; @@ -30,21 +29,20 @@ namespace HandyControlDemo.ViewModel #endif } - public RelayCommand AddItemCmd => new Lazy(() => - new RelayCommand(() => + public RelayCommand AddItemCmd => new(() => + { + if (string.IsNullOrEmpty(TagName)) { - if (string.IsNullOrEmpty(TagName)) - { - Growl.Warning(Lang.PlsEnterContent); - return; - } + Growl.Warning(Lang.PlsEnterContent); + return; + } - DataList.Insert(0, new DemoDataModel - { - IsSelected = DataList.Count % 2 == 0, - Name = TagName - }); - TagName = string.Empty; - })).Value; + DataList.Insert(0, new DemoDataModel + { + IsSelected = DataList.Count % 2 == 0, + Name = TagName + }); + TagName = string.Empty; + }); } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/WindowDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/WindowDemoViewModel.cs index 3527383d..227fac1b 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/WindowDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/WindowDemoViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Windows; +using System.Windows; using GalaSoft.MvvmLight.Command; using HandyControlDemo.Tools; @@ -7,7 +6,7 @@ namespace HandyControlDemo.ViewModel { public class WindowDemoViewModel { - public RelayCommand OpenWindowCmd => new Lazy>(() => new RelayCommand(OpenWindow)).Value; + public RelayCommand OpenWindowCmd => new(OpenWindow); private void OpenWindow(string windowTag) { diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs index fa400faf..d2b610fe 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs @@ -89,24 +89,18 @@ namespace HandyControlDemo.ViewModel /// /// 切换例子命令 /// - public RelayCommand SwitchDemoCmd => - new Lazy>(() => - new RelayCommand(SwitchDemo)).Value; + public RelayCommand SwitchDemoCmd => new(SwitchDemo); - public RelayCommand OpenPracticalDemoCmd => new Lazy(() => - new RelayCommand(OpenPracticalDemo)).Value; + public RelayCommand OpenPracticalDemoCmd => new(OpenPracticalDemo); - public RelayCommand GlobalShortcutInfoCmd => new Lazy(() => - new RelayCommand(() => Growl.Info("Global Shortcut Info"))).Value; + public RelayCommand GlobalShortcutInfoCmd => new(() => Growl.Info("Global Shortcut Info")); - public RelayCommand GlobalShortcutWarningCmd => new Lazy(() => - new RelayCommand(() => Growl.Warning("Global Shortcut Warning"))).Value; + public RelayCommand GlobalShortcutWarningCmd => new(() => Growl.Warning("Global Shortcut Warning")); - public RelayCommand OpenDocCmd => new Lazy(() => - new RelayCommand(() => - { - ControlCommands.OpenLink.Execute(_dataService.GetDemoUrl(DemoInfoCurrent, DemoItemCurrent)); - })).Value; + public RelayCommand OpenDocCmd => new(() => + { + ControlCommands.OpenLink.Execute(_dataService.GetDemoUrl(DemoInfoCurrent, DemoItemCurrent)); + }); #endregion diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/NonClientAreaViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/NonClientAreaViewModel.cs index 82c81c4f..4f2ecd43 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/NonClientAreaViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/NonClientAreaViewModel.cs @@ -1,5 +1,4 @@ -using System; -using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using HandyControlDemo.Data; @@ -14,8 +13,7 @@ namespace HandyControlDemo.ViewModel VersionInfo = VersionHelper.GetVersion(); } - public RelayCommand OpenViewCmd => new Lazy>(() => - new RelayCommand(OpenView)).Value; + public RelayCommand OpenViewCmd => new(OpenView); private void OpenView(string viewName) { diff --git a/src/Shared/HandyControl_Shared/Themes/Theme.cs b/src/Shared/HandyControl_Shared/Themes/Theme.cs index 6718f571..26742ac6 100644 --- a/src/Shared/HandyControl_Shared/Themes/Theme.cs +++ b/src/Shared/HandyControl_Shared/Themes/Theme.cs @@ -214,7 +214,13 @@ namespace HandyControl.Themes private void UpdateSkin() => MergedDictionaries[0] = GetSkin(Skin); - public virtual ResourceDictionary GetTheme() => ResourceHelper.GetTheme(); + private ResourceDictionary _theme; + + public virtual ResourceDictionary GetTheme() + { + _theme ??= ResourceHelper.GetTheme(); + return _theme; + } private void InitResource() { @@ -231,6 +237,6 @@ namespace HandyControl.Themes public class StandaloneTheme : Theme { - public override ResourceDictionary GetTheme() => ResourceHelper.GetTheme(true); + public override ResourceDictionary GetTheme() => ResourceHelper.GetTheme(); } } diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/ResourceHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/ResourceHelper.cs index 29840ca0..18c60220 100644 --- a/src/Shared/HandyControl_Shared/Tools/Helper/ResourceHelper.cs +++ b/src/Shared/HandyControl_Shared/Tools/Helper/ResourceHelper.cs @@ -79,28 +79,12 @@ namespace HandyControl.Tools Source = new Uri($"pack://application:,,,/HandyControl;component/Themes/Skin{skin}.xaml") }; - private static ResourceDictionary HcTheme; - /// /// get HandyControl theme /// - /// - public static ResourceDictionary GetTheme(bool standalone = false) + public static ResourceDictionary GetTheme() => new() { - if (!standalone) - { - HcTheme ??= new ResourceDictionary - { - Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml") - }; - - return HcTheme; - } - - return new ResourceDictionary - { - Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml") - }; - } + Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml") + }; } }