Skip to content

Commit

Permalink
Improve the performance of merged ResourceDictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed May 20, 2020
1 parent 2a89bf4 commit 39b1296
Show file tree
Hide file tree
Showing 144 changed files with 679 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
xmlns:system="clr-namespace:System;assembly=mscorlib">
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Geometries.xaml"/>
<ResourceDictionary Source="../../Basic/Converters.xaml"/>
<ResourceDictionary Source="../TextBlock.xaml"/>
<ResourceDictionary Source="../Button.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Geometries.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Converters.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/TextBlock.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Button.xaml"/>
</ResourceDictionary.MergedDictionaries>

<!--下拉框切换按钮-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Sizes.xaml"/>
<ResourceDictionary Source="../../Basic/Converters.xaml"/>
<ResourceDictionary Source="BaseStyle.xaml"/>
<ResourceDictionary Source="ScrollViewerBaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Sizes.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Converters.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/BaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/ScrollViewerBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>

<PathGeometry x:Key="TreeArrow" Figures="M508.893248 762.931659a65.039498 65.039498 0 0 1-46.420659-19.485839L97.125746 371.004022c-25.143018-25.634319-24.752868-66.816849 0.881451-91.959868 25.648769-25.164693 66.809624-24.745643 91.959867 0.881451l318.933409 325.125238 318.933408-325.125238a65.025048 65.025048 0 0 1 92.841318 91.078417L555.313907 743.44582a65.025048 65.025048 0 0 1-46.420659 19.485839z"/>
Expand Down
15 changes: 8 additions & 7 deletions src/Net_40/HandyControl_Net_40/Themes/Styles/DataGrid.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib">
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base/ScrollViewerBaseStyle.xaml"/>
<ResourceDictionary Source="Button.xaml"/>
<ResourceDictionary Source="ToggleButton.xaml"/>
<ResourceDictionary Source="TextBox.xaml"/>
<ResourceDictionary Source="ComboBox.xaml"/>
<ResourceDictionary Source="CheckBox.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/ScrollViewerBaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Button.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/ToggleButton.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/TextBox.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/ComboBox.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/CheckBox.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style x:Key="RowHeaderGripperStyle" TargetType="Thumb">
Expand Down
7 changes: 4 additions & 3 deletions src/Net_40/HandyControl_Net_40/Themes/Styles/ListView.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Basic/Sizes.xaml"/>
<ResourceDictionary Source="Base/ScrollViewerBaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Sizes.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/ScrollViewerBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style x:Key="GridViewColumnHeaderGripper" TargetType="Thumb">
Expand Down
5 changes: 3 additions & 2 deletions src/Net_40/HandyControl_Net_40/Themes/Styles/MessageBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
xmlns:langs="clr-namespace:HandyControl.Properties.Langs"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
xmlns:ex="clr-namespace:HandyControl.Tools.Extension">
xmlns:ex="clr-namespace:HandyControl.Tools.Extension"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Window.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Window.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style TargetType="controls:MessageBox" BasedOn="{StaticResource WindowWin10}">
Expand Down
8 changes: 4 additions & 4 deletions src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
xmlns:tools="clr-namespace:HandyControl.Tools">
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Button.xaml"/>
<ResourceDictionary Source="../Basic/Converters.xaml"/>
<ResourceDictionary Source="../Basic/Geometries.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Button.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Converters.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Geometries.xaml"/>
</ResourceDictionary.MergedDictionaries>

<LinearGradientBrush x:Key="ResizeGripperForeground" EndPoint="1,0.75" StartPoint="0,0.25">
Expand Down
3 changes: 2 additions & 1 deletion src/Shared/HandyControlDemo_Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using System.Windows;
using HandyControl.Data;
using HandyControl.Themes;
using HandyControl.Tools;
using HandyControlDemo.Data;
using HandyControlDemo.Tools;
Expand Down Expand Up @@ -72,7 +73,6 @@ protected override void OnStartup(StartupEventArgs e)
UpdateSkin(GlobalData.Config.Skin);
}

ConfigHelper.Instance.SetSystemVersionInfo(CommonHelper.GetSystemVersionInfo());
ConfigHelper.Instance.SetWindowDefaultStyle();
ConfigHelper.Instance.SetNavigationWindowDefaultStyle();

Expand All @@ -88,6 +88,7 @@ protected override void OnExit(ExitEventArgs e)

internal void UpdateSkin(SkinType skin)
{
SharedResourceDictionary.SharedDictionaries.Clear();
var skins0 = Resources.MergedDictionaries[0];
skins0.MergedDictionaries.Clear();
skins0.MergedDictionaries.Add(ResourceHelper.GetSkin(skin));
Expand Down
2 changes: 2 additions & 0 deletions src/Shared/HandyControlDemo_Shared/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using GalaSoft.MvvmLight.Messaging;
using HandyControl.Controls;
using HandyControl.Tools;
using HandyControlDemo.Data;
using HandyControlDemo.Tools;

Expand All @@ -18,6 +19,7 @@ protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);

ConfigHelper.Instance.SetSystemVersionInfo(CommonHelper.GetSystemVersionInfo());
Messenger.Default.Send(true, MessageToken.FullSwitch);
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace HandyControl.Controls
{
internal class WatermarkTextBox : TextBox
public class WatermarkTextBox : TextBox
{
#region Public Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\ContrastEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\EffectBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\GrayScaleEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Themes\SharedResourceDictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Themes\Theme.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\BorderCircularClipConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" />
Expand Down
19 changes: 10 additions & 9 deletions src/Shared/HandyControl_Shared/Themes/Basic/Basic.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>

<ResourceDictionary Source="../Basic/Brushes.xaml"/>
<ResourceDictionary Source="../Basic/Converters.xaml"/>
<ResourceDictionary Source="../Basic/Effects.xaml"/>
<ResourceDictionary Source="../Basic/Fonts.xaml"/>
<ResourceDictionary Source="../Basic/Geometries.xaml"/>
<ResourceDictionary Source="../Basic/Paths.xaml"/>
<ResourceDictionary Source="../Basic/Sizes.xaml"/>
<ResourceDictionary Source="../Basic/Behaviors.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Brushes.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Converters.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Effects.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Fonts.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Geometries.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Paths.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Sizes.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Behaviors.xaml"/>

</ResourceDictionary.MergedDictionaries>

Expand Down
5 changes: 3 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/Basic/Paths.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Geometries.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Geometries.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style TargetType="Path">
Expand Down
39 changes: 39 additions & 0 deletions src/Shared/HandyControl_Shared/Themes/SharedResourceDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Windows;
using HandyControl.Tools;

namespace HandyControl.Themes
{
public class SharedResourceDictionary : ResourceDictionary
{
public static Dictionary<Uri, ResourceDictionary> SharedDictionaries = new Dictionary<Uri, ResourceDictionary>();

private Uri _sourceUri;

public new Uri Source
{
get => DesignerHelper.IsInDesignMode ? base.Source : _sourceUri;
set
{
if (value == null) return;
if (DesignerHelper.IsInDesignMode)
{
base.Source = value;
return;
}
_sourceUri = value;

if (!SharedDictionaries.ContainsKey(value))
{
base.Source = value;
SharedDictionaries.Add(value, this);
}
else
{
MergedDictionaries.Add(SharedDictionaries[value]);
}
}
}
}
}
5 changes: 3 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/SkinDark.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Basic/Colors/ColorsDark.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Colors/ColorsDark.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
5 changes: 3 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/SkinDefault.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Basic/Colors/Colors.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Colors/Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
5 changes: 3 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/SkinViolet.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Basic/Colors/ColorsViolet.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Colors/ColorsViolet.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
5 changes: 3 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/Styles/Badge.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base/BadgeBaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/BadgeBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style BasedOn="{StaticResource BadgeBaseStyle}" TargetType="controls:Badge">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Border.xaml" />
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Border.xaml" />
</ResourceDictionary.MergedDictionaries>

<SineEase x:Key="SineEaseOut" EasingMode="EaseOut" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Fonts.xaml"/>
<ResourceDictionary Source="../Rectangle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Fonts.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Rectangle.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style x:Key="FocusVisual">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="BaseStyle.xaml"/>
<ResourceDictionary Source="../../Basic/Sizes.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/BaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Basic/Sizes.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style x:Key="ButtonBaseBaseStyle" BasedOn="{StaticResource BaseStyle}" TargetType="ButtonBase">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
xmlns:controls="clr-namespace:HandyControl.Controls"
xmlns:themes="clr-namespace:HandyControl.Themes">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ButtonBaseBaseStyle.xaml"/>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/Base/ButtonBaseBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Style x:Key="ButtonBaseStyle" BasedOn="{StaticResource ButtonBaseBaseStyle}" TargetType="Button">
Expand Down
Loading

0 comments on commit 39b1296

Please sign in to comment.