Skip to content

Commit

Permalink
optimized demo start-up speed
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed May 23, 2020
1 parent b57e6e8 commit aa745e3
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@
<DefineConstants>TRACE;Core</DefineConstants>
<TargetFramework>netcoreapp3.0</TargetFramework>
<NoWarn>0067;0649</NoWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningsAsErrors></WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Core31|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>0067;0649</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Core30|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DocumentationFile>C:\Code\GitHub\HandyControl\src\Core_GE30\HandyControl_Core_GE30\HandyControl.xml</DocumentationFile>
<NoWarn>0067;0649;1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Core31|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DocumentationFile>C:\Code\GitHub\HandyControl\src\Core_GE30\HandyControl_Core_GE30\HandyControl.xml</DocumentationFile>
<NoWarn>0067;0649;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<netVersion>netgt40</netVersion>
<LangVersion>8.0</LangVersion>
<NoWarn>0067;0649;1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release-Net47|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -99,6 +100,7 @@
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<netVersion>netgt40</netVersion>
<LangVersion>8.0</LangVersion>
<NoWarn>0067;0649;1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-Net48|AnyCPU'">
<DebugType>pdbonly</DebugType>
Expand All @@ -111,6 +113,7 @@
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<netVersion>netgt40</netVersion>
<LangVersion>8.0</LangVersion>
<NoWarn>0067;0649;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\NetAssemblyInfo.cs">
Expand Down
1 change: 1 addition & 0 deletions src/Shared/HandyControlDemo_Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Main\BlogsView.xaml.cs">
<DependentUpon>BlogsView.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Main\MainWindowContent.xaml.cs">
<DependentUpon>MainWindowContent.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Main\NoUserContent.xaml.cs">
<DependentUpon>NoUserContent.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -765,6 +768,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Main\MainWindowContent.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Main\NoUserContent.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down

This file was deleted.

28 changes: 1 addition & 27 deletions src/Shared/HandyControlDemo_Shared/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<hc:GlobalShortcut.KeyBindings>
<KeyBinding Modifiers="Control+Alt" Key="I" Command="{Binding Main.GlobalShortcutInfoCmd, Source={StaticResource Locator}}"/>
<KeyBinding Modifiers="Control+Alt" Key="E" Command="{Binding Main.GlobalShortcutWarningCmd, Source={StaticResource Locator}}"/>
</hc:GlobalShortcut.KeyBindings>
<hc:Window.NonClientAreaContent>
<userControl:NoUserContent/>
</hc:Window.NonClientAreaContent>
<Border BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}" Background="{StaticResource CloudDrawingBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240" MinWidth="240" MaxWidth="400"/>
<ColumnDefinition MinWidth="200"/>
</Grid.ColumnDefinitions>
<userControl:LeftMainContent/>
<userControl:MainContent Grid.Column="1" d:IsHidden="true"/>
<GridSplitter Margin="0,26,10,26" Grid.Column="0" HorizontalAlignment="Right" Width="4" Background="Transparent"/>
<hc:ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right" IsInertiaEnabled="True" IsPenetrating="True">
<StackPanel hc:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10"/>
</hc:ScrollViewer>
</Grid>
</Border>
<ContentControl Name="ControlMain"/>
</hc:Window>
27 changes: 20 additions & 7 deletions src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<KeyBinding>
{
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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Shared/HandyControlDemo_Shared/Resources/DemoTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:hc="https://handyorg.github.io/handycontrol"
BorderThickness="0,1,0,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{StaticResource CloudDrawingBrush}"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
x:Class="HandyControlDemo.UserControl.MainWindowContent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240" MinWidth="240" MaxWidth="400"/>
<ColumnDefinition MinWidth="200"/>
</Grid.ColumnDefinitions>
<userControl:LeftMainContent/>
<userControl:MainContent Grid.Column="1"/>
<GridSplitter Margin="0,26,10,26" Grid.Column="0" HorizontalAlignment="Right" Width="4" Background="Transparent"/>
<hc:ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right" IsInertiaEnabled="True" IsPenetrating="True">
<StackPanel hc:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10"/>
</hc:ScrollViewer>
</Grid>
</Border>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl
{
public partial class MainWindowContent
{
public MainWindowContent()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public MainViewModel(DataService dataService)
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
});

DataList = dataService.GetDemoDataList();
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();

#if netle40
Task.Factory.StartNew(() =>
{
DataList = dataService.GetDemoDataList();
foreach (var item in dataService.GetDemoInfo())
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
Expand All @@ -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(() =>
Expand Down
10 changes: 5 additions & 5 deletions src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint>(ResourceToken.BlurGradientValue);
var color = ColorHelper.ToColor(colorValue);
Expand All @@ -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;

Expand Down
47 changes: 35 additions & 12 deletions src/Shared/HandyControl_Shared/Themes/Theme.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.ObjectModel;
using System.Windows;
using HandyControl.Data;
using HandyControl.Tools;
Expand All @@ -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;

Expand All @@ -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<ResourceDictionary> MergedDictionaries => throw new NotSupportedException();
}
}
9 changes: 4 additions & 5 deletions src/Shared/HandyControl_Shared/Tools/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down

0 comments on commit aa745e3

Please sign in to comment.