优化更新代码,添加界面功能并整合
This commit is contained in:
79
WPFluent/Services/ThemeService.cs
Normal file
79
WPFluent/Services/ThemeService.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Appearance;
|
||||
|
||||
namespace WPFluent;
|
||||
|
||||
/// <summary>
|
||||
/// Lets you set the app theme.
|
||||
/// </summary>
|
||||
public partial class ThemeService : IThemeService
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public virtual SystemTheme GetNativeSystemTheme() => ApplicationThemeManager.GetSystemTheme();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual ApplicationTheme GetSystemTheme()
|
||||
{
|
||||
SystemTheme systemTheme = ApplicationThemeManager.GetSystemTheme();
|
||||
|
||||
return systemTheme switch
|
||||
{
|
||||
SystemTheme.Light => ApplicationTheme.Light,
|
||||
SystemTheme.Dark => ApplicationTheme.Dark,
|
||||
SystemTheme.Glow => ApplicationTheme.Dark,
|
||||
SystemTheme.CapturedMotion => ApplicationTheme.Dark,
|
||||
SystemTheme.Sunrise => ApplicationTheme.Light,
|
||||
SystemTheme.Flow => ApplicationTheme.Light,
|
||||
SystemTheme.HCBlack => ApplicationTheme.HighContrast,
|
||||
SystemTheme.HC1 => ApplicationTheme.HighContrast,
|
||||
SystemTheme.HC2 => ApplicationTheme.HighContrast,
|
||||
SystemTheme.HCWhite => ApplicationTheme.HighContrast,
|
||||
_ => ApplicationTheme.Unknown,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual ApplicationTheme GetTheme() => ApplicationThemeManager.GetAppTheme();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool SetAccent(Color accentColor)
|
||||
{
|
||||
ApplicationAccentColorManager.Apply(accentColor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool SetAccent(SolidColorBrush accentSolidBrush)
|
||||
{
|
||||
Color color = accentSolidBrush.Color;
|
||||
color.A = (byte)Math.Round(accentSolidBrush.Opacity * byte.MaxValue);
|
||||
|
||||
ApplicationAccentColorManager.Apply(color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool SetSystemAccent()
|
||||
{
|
||||
ApplicationAccentColorManager.ApplySystemAccent();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool SetTheme(ApplicationTheme applicationTheme)
|
||||
{
|
||||
if(ApplicationThemeManager.GetAppTheme() == applicationTheme)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ApplicationThemeManager.Apply(applicationTheme);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user