close #361
This commit is contained in:
1 parent
61ee9a5337
commit
8f1bb42714
9 files changed
+80
-26
No files matched your search
@@ -8,24 +8,15 @@
|
|||||||
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
||||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||||
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
|
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
|
||||||
|
xmlns:resources="clr-namespace:HandyControlDemo.Resources"
|
||||||
d1P1:Ignorable="d"
|
d1P1:Ignorable="d"
|
||||||
StartupUri="MainWindow.xaml">
|
StartupUri="MainWindow.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceDictionary>
|
<hc:Theme Name="HandyTheme"/>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<resources:DemoTheme Name="DemoTheme"/>
|
||||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
|
|
||||||
<ResourceDictionary Source="Resources/Themes/SkinDefault.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
</ResourceDictionary>
|
|
||||||
<ResourceDictionary>
|
|
||||||
<ResourceDictionary.MergedDictionaries>
|
|
||||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
|
|
||||||
<ResourceDictionary Source="Resources/Themes/Theme.xaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
|
||||||
</ResourceDictionary>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<langs:LangDecorator x:Key="DemoLangs"/>
|
<langs:LangDecorator x:Key="DemoLangs"/>
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
#if !netle40
|
||||||
using System.Runtime;
|
using System.Runtime;
|
||||||
|
#endif
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -86,21 +88,9 @@ namespace HandyControlDemo
|
|||||||
|
|
||||||
internal void UpdateSkin(SkinType skin)
|
internal void UpdateSkin(SkinType skin)
|
||||||
{
|
{
|
||||||
var skins0 = Resources.MergedDictionaries[0];
|
ResourceHelper.GetTheme("HandyTheme", Resources).Skin = skin;
|
||||||
skins0.MergedDictionaries.Clear();
|
ResourceHelper.GetTheme("DemoTheme", Resources).Skin = skin;
|
||||||
skins0.MergedDictionaries.Add(ResourceHelper.GetSkin(skin));
|
|
||||||
skins0.MergedDictionaries.Add(ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skin));
|
|
||||||
|
|
||||||
var skins1 = Resources.MergedDictionaries[1];
|
|
||||||
skins1.MergedDictionaries.Clear();
|
|
||||||
skins1.MergedDictionaries.Add(new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
|
|
||||||
});
|
|
||||||
skins1.MergedDictionaries.Add(new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml")
|
|
||||||
});
|
|
||||||
Current.MainWindow?.OnApplyTemplate();
|
Current.MainWindow?.OnApplyTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Resources\DemoTheme.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Service\Data\DataService.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Service\Data\DataService.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\HatchBrushConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\HatchBrushConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\String2BrushConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\String2BrushConverter.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Themes;
|
||||||
|
using HandyControl.Tools;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\ContrastEffect.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\ContrastEffect.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\EffectBase.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\EffectBase.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\GrayScaleEffect.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\BorderCircularClipConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\CornerRadiusSplitConverter.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.Media.Effects")]
|
||||||
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Data")]
|
[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.Properties.Langs")]
|
||||||
|
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Themes")]
|
||||||
[assembly: XmlnsPrefix("https://handyorg.github.io/handycontrol", "hc")]
|
[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.Media.Effects")]
|
||||||
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Data")]
|
[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.Properties.Langs")]
|
||||||
|
[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Themes")]
|
||||||
[assembly: XmlnsPrefix("https://handyorg.github.io/handycontrol", "hc")]
|
[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.Reflection;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Themes;
|
||||||
|
|
||||||
namespace HandyControl.Tools
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user