From aa745e32b1f3b3416353284553981322f52e7f3f Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Sat, 23 May 2020 15:21:24 +0800
Subject: [PATCH] optimized demo start-up speed
---
.../HandyControl_Core_GE30.csproj | 6 +--
.../HandyControl_Net_GE45.csproj | 3 ++
.../HandyControlDemo_Shared/App.xaml.cs | 1 +
.../HandyControlDemo_Shared.projitems | 7 +++
.../HandyControlDemo_Shared.shproj.user | 6 ---
.../HandyControlDemo_Shared/MainWindow.xaml | 28 +----------
.../MainWindow.xaml.cs | 27 ++++++++---
.../Resources/DemoTheme.cs | 7 ++-
.../UserControl/Main/MainWindowContent.xaml | 21 +++++++++
.../Main/MainWindowContent.xaml.cs | 10 ++++
.../ViewModel/Main/MainViewModel.cs | 3 +-
.../Controls/Window/BlurWindow.cs | 10 ++--
.../HandyControl_Shared/Themes/Theme.cs | 47 ++++++++++++++-----
.../Tools/Helper/ConfigHelper.cs | 9 ++--
14 files changed, 116 insertions(+), 69 deletions(-)
delete mode 100644 src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.shproj.user
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml.cs
diff --git a/src/Core_GE30/HandyControl_Core_GE30/HandyControl_Core_GE30.csproj b/src/Core_GE30/HandyControl_Core_GE30/HandyControl_Core_GE30.csproj
index df7c660e8..f56a2141f 100644
--- a/src/Core_GE30/HandyControl_Core_GE30/HandyControl_Core_GE30.csproj
+++ b/src/Core_GE30/HandyControl_Core_GE30/HandyControl_Core_GE30.csproj
@@ -18,22 +18,20 @@
TRACE;Core
netcoreapp3.0
0067;0649
- false
-
TRACE;Core
netcoreapp3.1
+ 0067;0649
TRACE;Core
netcoreapp3.0
- C:\Code\GitHub\HandyControl\src\Core_GE30\HandyControl_Core_GE30\HandyControl.xml
+ 0067;0649;1591
TRACE;Core
netcoreapp3.1
- C:\Code\GitHub\HandyControl\src\Core_GE30\HandyControl_Core_GE30\HandyControl.xml
0067;0649;1591
diff --git a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
index f6e750cf4..ea78f6077 100644
--- a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
@@ -87,6 +87,7 @@
v4.6.2
netgt40
8.0
+ 0067;0649;1591
pdbonly
@@ -99,6 +100,7 @@
v4.7
netgt40
8.0
+ 0067;0649;1591
pdbonly
@@ -111,6 +113,7 @@
v4.8
netgt40
8.0
+ 0067;0649;1591
diff --git a/src/Shared/HandyControlDemo_Shared/App.xaml.cs b/src/Shared/HandyControlDemo_Shared/App.xaml.cs
index 7bbb795cd..3393add02 100644
--- a/src/Shared/HandyControlDemo_Shared/App.xaml.cs
+++ b/src/Shared/HandyControlDemo_Shared/App.xaml.cs
@@ -73,6 +73,7 @@ protected override void OnStartup(StartupEventArgs e)
UpdateSkin(GlobalData.Config.Skin);
}
+ ConfigHelper.Instance.SystemVersionInfo = CommonHelper.GetSystemVersionInfo();
ConfigHelper.Instance.SetWindowDefaultStyle();
ConfigHelper.Instance.SetNavigationWindowDefaultStyle();
diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index 2dbff989d..b28427b08 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -249,6 +249,9 @@
BlogsView.xaml
+
+ MainWindowContent.xaml
+
NoUserContent.xaml
@@ -765,6 +768,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.shproj.user b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.shproj.user
deleted file mode 100644
index baf24173c..000000000
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.shproj.user
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
- false
-
-
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml
index 0e779e8a7..c97e6fe20 100644
--- a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml
+++ b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml
@@ -4,40 +4,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
- xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
- xmlns:data="clr-namespace:HandyControlDemo.Data"
mc:Ignorable="d"
Title="HandyControlDemo"
ShowTitle="False"
Background="{DynamicResource SecondaryRegionBrush}"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen"
- DataContext="{Binding Main,Source={StaticResource Locator}}"
- hc:GlobalShortcut.Host="True"
- hc:Dialog.Token="{x:Static data:MessageToken.MainWindow}"
- hc:WindowAttach.IgnoreAltF4="True"
d:DesignHeight="800"
d:DesignWidth="1400"
Icon="/HandyControlDemo;component/Resources/Img/icon.ico">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs
index 25d2274f9..59baef023 100644
--- a/src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs
+++ b/src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs
@@ -1,25 +1,38 @@
using System;
+using System.Collections.Generic;
using System.ComponentModel;
+using System.Windows.Input;
using GalaSoft.MvvmLight.Messaging;
using HandyControl.Controls;
using HandyControl.Tools;
using HandyControlDemo.Data;
using HandyControlDemo.Tools;
+using HandyControlDemo.UserControl;
+using HandyControlDemo.ViewModel;
namespace HandyControlDemo
{
public partial class MainWindow
{
- public MainWindow()
- {
- InitializeComponent();
- }
+ public MainWindow() => InitializeComponent();
- protected override void OnInitialized(EventArgs e)
+ protected override void OnContentRendered(EventArgs e)
{
- base.OnInitialized(e);
+ base.OnContentRendered(e);
+
+ DataContext = ViewModelLocator.Instance.Main;
+ NonClientAreaContent = new NoUserContent();
+ ControlMain.Content = new MainWindowContent();
+
+ GlobalShortcut.Init(new List
+ {
+ new KeyBinding(ViewModelLocator.Instance.Main.GlobalShortcutInfoCmd, Key.I, ModifierKeys.Control | ModifierKeys.Alt),
+ new KeyBinding(ViewModelLocator.Instance.Main.GlobalShortcutWarningCmd, Key.E, ModifierKeys.Control | ModifierKeys.Alt)
+ });
+
+ Dialog.SetToken(this, MessageToken.MainWindow);
+ WindowAttach.SetIgnoreAltF4(this, true);
- ConfigHelper.Instance.SetSystemVersionInfo(CommonHelper.GetSystemVersionInfo());
Messenger.Default.Send(true, MessageToken.FullSwitch);
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
}
diff --git a/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs b/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs
index fdfba9adf..d9d22af42 100644
--- a/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs
+++ b/src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs
@@ -8,9 +8,12 @@ namespace HandyControlDemo.Resources
{
public class DemoTheme : Theme
{
- public override Uri ThemeUri => new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml");
-
public override ResourceDictionary GetSkin(SkinType skinType) =>
ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skinType);
+
+ public override ResourceDictionary GetTheme() => new ResourceDictionary
+ {
+ Source = new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml")
+ };
}
}
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml
new file mode 100644
index 000000000..28866da58
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml.cs
new file mode 100644
index 000000000..3357b4dc5
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainWindowContent.xaml.cs
@@ -0,0 +1,10 @@
+namespace HandyControlDemo.UserControl
+{
+ public partial class MainWindowContent
+ {
+ public MainWindowContent()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs
index 573c41f09..b631d91c6 100644
--- a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs
@@ -57,12 +57,12 @@ public MainViewModel(DataService dataService)
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
});
- DataList = dataService.GetDemoDataList();
DemoInfoCollection = new ObservableCollection();
#if netle40
Task.Factory.StartNew(() =>
{
+ DataList = dataService.GetDemoDataList();
foreach (var item in dataService.GetDemoInfo())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
@@ -74,6 +74,7 @@ public MainViewModel(DataService dataService)
#else
Task.Run(() =>
{
+ DataList = dataService.GetDemoDataList();
foreach (var item in dataService.GetDemoInfo())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
diff --git a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs
index f070ce451..63c874c01 100644
--- a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs
@@ -20,12 +20,12 @@ public override void OnApplyTemplate()
EnableBlur(this);
}
- public static SystemVersionInfo SystemVersionInfo { get; set; }
-
internal static void EnableBlur(Window window)
{
- if (SystemVersionInfo < SystemVersionInfo.Windows10 ||
- SystemVersionInfo >= SystemVersionInfo.Windows10_1903)
+ var versionInfo = ConfigHelper.Instance.SystemVersionInfo;
+
+ if (versionInfo < SystemVersionInfo.Windows10 ||
+ versionInfo >= SystemVersionInfo.Windows10_1903)
{
var colorValue = ResourceHelper.GetResource(ResourceToken.BlurGradientValue);
var color = ColorHelper.ToColor(colorValue);
@@ -37,7 +37,7 @@ internal static void EnableBlur(Window window)
var accentPolicy = new InteropValues.ACCENTPOLICY();
var accentPolicySize = Marshal.SizeOf(accentPolicy);
- accentPolicy.AccentState = SystemVersionInfo < SystemVersionInfo.Windows10_1809
+ accentPolicy.AccentState = versionInfo < SystemVersionInfo.Windows10_1809
? InteropValues.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND
: InteropValues.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND;
diff --git a/src/Shared/HandyControl_Shared/Themes/Theme.cs b/src/Shared/HandyControl_Shared/Themes/Theme.cs
index 25ac51e59..29d9726b3 100644
--- a/src/Shared/HandyControl_Shared/Themes/Theme.cs
+++ b/src/Shared/HandyControl_Shared/Themes/Theme.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.ObjectModel;
using System.Windows;
using HandyControl.Data;
using HandyControl.Tools;
@@ -8,7 +7,32 @@ namespace HandyControl.Themes
{
public class Theme : ResourceDictionary
{
- public Theme() => UpdateResource();
+ public Theme()
+ {
+ if (DesignerHelper.IsInDesignMode)
+ {
+ MergedDictionaries.Add(new ResourceDictionary
+ {
+ Source = new Uri("pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml")
+ });
+ MergedDictionaries.Add(new ResourceDictionary
+ {
+ Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
+ });
+ }
+ else
+ {
+ UpdateResource();
+ }
+ }
+
+ private Uri _source;
+
+ public new Uri Source
+ {
+ get => DesignerHelper.IsInDesignMode ? null : _source;
+ set => _source = value;
+ }
private SkinType _skin;
@@ -26,20 +50,19 @@ public virtual SkinType Skin
public string Name { get; set; }
- public virtual Uri ThemeUri => new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml");
-
public virtual ResourceDictionary GetSkin(SkinType skinType) => ResourceHelper.GetSkin(skinType);
+ public virtual ResourceDictionary GetTheme() => new ResourceDictionary
+ {
+ Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
+ };
+
private void UpdateResource()
{
- base.MergedDictionaries.Clear();
- base.MergedDictionaries.Add(GetSkin(Skin));
- base.MergedDictionaries.Add(new ResourceDictionary
- {
- Source = ThemeUri
- });
+ if (DesignerHelper.IsInDesignMode) return;
+ MergedDictionaries.Clear();
+ MergedDictionaries.Add(GetSkin(Skin));
+ MergedDictionaries.Add(GetTheme());
}
-
- public new Collection MergedDictionaries => throw new NotSupportedException();
}
}
diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs
index 65e2c1cd5..47236686f 100644
--- a/src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs
@@ -8,7 +8,6 @@
using System.Windows.Markup;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
-using HandyControl.Controls;
using HandyControl.Data;
using HandyControl.Properties.Langs;
@@ -38,7 +37,7 @@ public XmlLanguage Lang
}
}
- public void SetSystemVersionInfo(SystemVersionInfo info) => BlurWindow.SystemVersionInfo = info;
+ public SystemVersionInfo SystemVersionInfo { get; set; }
public void SetLang(string lang)
{
@@ -49,7 +48,7 @@ public void SetLang(string lang)
public void SetConfig(HandyControlConfig config)
{
- SetSystemVersionInfo(config.SystemVersionInfo);
+ SystemVersionInfo = config.SystemVersionInfo;
SetLang(config.Lang);
SetTimelineFrameRate(config.TimelineFrameRate);
}
@@ -60,10 +59,10 @@ public void SetTimelineFrameRate(int rate) =>
public void SetWindowDefaultStyle(object resourceKey = null)
{
var metadata = resourceKey == null
- ? new FrameworkPropertyMetadata(Application.Current.FindResource(typeof(System.Windows.Window)))
+ ? new FrameworkPropertyMetadata(Application.Current.FindResource(typeof(Window)))
: new FrameworkPropertyMetadata(Application.Current.FindResource(resourceKey));
- FrameworkElement.StyleProperty.OverrideMetadata(typeof(System.Windows.Window), metadata);
+ FrameworkElement.StyleProperty.OverrideMetadata(typeof(Window), metadata);
}
public void SetNavigationWindowDefaultStyle(object resourceKey = null)