This commit is contained in:
NaBian committed 2020-04-19 14:58:48 +08:00
1 parent 61ee9a5337
commit 8f1bb42714
9 files changed
+80 -26

No files matched your search

@@ -84,6 +84,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\Theme.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\BorderCircularClipConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\CornerRadiusSplitConverter.cs" />
@@ -10,4 +10,5 @@
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Media.Effects")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Data")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Properties.Langs")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Themes")]
[assembly: XmlnsPrefix("https://handyorg.github.io/handycontrol", "hc")]
@@ -23,4 +23,5 @@ using System.Runtime.InteropServices;
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Media.Effects")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Data")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Properties.Langs")]
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Themes")]
[assembly: XmlnsPrefix("https://handyorg.github.io/handycontrol", "hc")]
@@ -0,0 +1,45 @@
using System;
using System.Collections.ObjectModel;
using System.Windows;
using HandyControl.Data;
using HandyControl.Tools;
namespace HandyControl.Themes
{
public class Theme : ResourceDictionary
{
public Theme() => UpdateResource();
private SkinType _skin;
public virtual SkinType Skin
{
get => _skin;
set
{
if (_skin == value) return;
_skin = value;
UpdateResource();
}
}
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);
private void UpdateResource()
{
base.MergedDictionaries.Clear();
base.MergedDictionaries.Add(GetSkin(Skin));
base.MergedDictionaries.Add(new ResourceDictionary
{
Source = ThemeUri
});
}
public new Collection<ResourceDictionary> MergedDictionaries => throw new NotSupportedException();
}
}
@@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection;
using System.Windows;
using HandyControl.Data;
using HandyControl.Themes;
namespace HandyControl.Tools
{
@@ -85,5 +86,12 @@ namespace HandyControl.Tools
};
}
}
public static Theme GetTheme(string name, ResourceDictionary resourceDictionary)
{
if (string.IsNullOrEmpty(name) || resourceDictionary == null) return null;
return resourceDictionary.MergedDictionaries.OfType<Theme>()
.FirstOrDefault(item => Equals(item.Name, name));
}
}
}