2020-08-07 02:16:25 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-07-25 06:46:29 +08:00
|
|
|
|
using System;
|
2020-10-30 05:24:16 +08:00
|
|
|
|
using System.Globalization;
|
2020-10-23 00:45:48 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
2020-07-25 03:02:56 +08:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Data;
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Converters
|
|
|
|
|
{
|
|
|
|
|
public sealed class ModuleEnabledToForegroundConverter : IValueConverter
|
|
|
|
|
{
|
2020-11-03 01:33:43 +08:00
|
|
|
|
private readonly ISettingsUtils settingsUtils = new SettingsUtils();
|
2020-09-22 01:14:44 +08:00
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private string selectedTheme = string.Empty;
|
|
|
|
|
|
2020-07-25 03:02:56 +08:00
|
|
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
|
|
|
{
|
|
|
|
|
bool isEnabled = (bool)value;
|
2020-07-30 02:38:03 +08:00
|
|
|
|
|
|
|
|
|
var defaultTheme = new Windows.UI.ViewManagement.UISettings();
|
|
|
|
|
|
2020-10-30 05:24:16 +08:00
|
|
|
|
// Using InvariantCulture as this is an internal string and expected to be in hexadecimal
|
|
|
|
|
var uiTheme = defaultTheme.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background).ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
// Normalize strings to uppercase according to Fxcop
|
|
|
|
|
selectedTheme = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.Theme.ToUpperInvariant();
|
|
|
|
|
|
|
|
|
|
if (selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && uiTheme == "#FF000000"))
|
2020-07-25 03:02:56 +08:00
|
|
|
|
{
|
2020-07-30 02:38:03 +08:00
|
|
|
|
// DARK
|
|
|
|
|
if (isEnabled)
|
|
|
|
|
{
|
|
|
|
|
return (SolidColorBrush)Application.Current.Resources["DarkForegroundBrush"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (SolidColorBrush)Application.Current.Resources["DarkForegroundDisabledBrush"];
|
|
|
|
|
}
|
2020-07-25 03:02:56 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-30 02:38:03 +08:00
|
|
|
|
// LIGHT
|
|
|
|
|
if (isEnabled)
|
|
|
|
|
{
|
|
|
|
|
return (SolidColorBrush)Application.Current.Resources["LightForegroundBrush"];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (SolidColorBrush)Application.Current.Resources["LightForegroundDisabledBrush"];
|
|
|
|
|
}
|
2020-07-25 03:02:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-25 06:46:29 +08:00
|
|
|
|
}
|