コード例 #1
0
        public static void ApplyThemeResourcesFromTheme([NotNull] ResourceDictionary resources, [NotNull] Theme newTheme)
        {
            if (resources.IsNull())
            {
                throw new ArgumentNullException(nameof(resources));
            }

            if (newTheme.IsNull())
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            ApplyResourceDictionary(newTheme.Resources, resources);
        }
コード例 #2
0
        public static Theme ChangeTheme([NotNull] ResourceDictionary resourceDictionary, [NotNull] Theme newTheme)
        {
            if (resourceDictionary.IsNull())
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }

            if (newTheme.IsNull())
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            var oldTheme = DetectTheme(resourceDictionary);

            return(ChangeTheme(resourceDictionary, oldTheme, newTheme));
        }
コード例 #3
0
        public static Theme ChangeTheme([NotNull] Window window, [NotNull] Theme newTheme)
        {
            if (window.IsNull())
            {
                throw new ArgumentNullException(nameof(window));
            }

            if (newTheme.IsNull())
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            var oldTheme = DetectTheme(window);

            return(ChangeTheme(window.Resources, oldTheme, newTheme));
        }
コード例 #4
0
        public static Theme ChangeTheme([NotNull] Application app, [NotNull] Theme newTheme)
        {
            if (app.IsNull())
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (newTheme.IsNull())
            {
                throw new ArgumentNullException(nameof(newTheme));
            }

            var oldTheme = DetectTheme(app);

            return(ChangeTheme(app.Resources, oldTheme, newTheme));
        }
コード例 #5
0
        /// <summary>
        /// Gets the inverse <see cref="Theme" /> of the given <see cref="Theme"/>.
        /// This method relies on the "Dark" or "Light" affix to be present.
        /// </summary>
        /// <param name="theme">The app theme.</param>
        /// <returns>The inverse <see cref="Theme"/> or <c>null</c> if it couldn't be found.</returns>
        /// <remarks>
        /// Returns BaseLight, if BaseDark is given or vice versa.
        /// Custom Themes must end with "Dark" or "Light" for this to work, for example "CustomDark" and "CustomLight".
        /// </remarks>
        public static Theme GetInverseTheme([NotNull] Theme theme)
        {
            if (theme.IsNull())
            {
                throw new ArgumentNullException(nameof(theme));
            }

            if (theme.Name.StartsWith("dark.", StringComparison.OrdinalIgnoreCase))
            {
                return(GetTheme("Light." + theme.Name.Substring("dark.".Length)));
            }

            if (theme.Name.StartsWith("light.", StringComparison.OrdinalIgnoreCase))
            {
                return(GetTheme("Dark." + theme.Name.Substring("light.".Length)));
            }

            return(null);
        }
コード例 #6
0
ファイル: ThemeManager.cs プロジェクト: 1143910315/MusicPlay2
        /// <summary>
        /// Gets the inverse <see cref="Theme" /> of the given <see cref="Theme"/>.
        /// This method relies on the "Dark" or "Light" affix to be present.
        /// </summary>
        /// <param name="theme">The app theme.</param>
        /// <returns>The inverse <see cref="Theme"/> or <c>null</c> if it couldn't be found.</returns>
        /// <remarks>
        /// Returns BaseLight, if BaseDark is given or vice versa.
        /// Custom Themes must end with "Dark" or "Light" for this to work, for example "CustomDark" and "CustomLight".
        /// </remarks>
        public static Theme GetInverseTheme([NotNull] Theme theme)
        {
            if (theme.IsNull())
            {
                throw new ArgumentNullException(nameof(theme));
            }

            if (theme.Type == ThemeType.Dark)
            {
                return(GetTheme("Light." + theme.Name.Substring("dark.".Length)));
            }

            if (theme.Type == ThemeType.Light)
            {
                return(GetTheme("Dark." + theme.Name.Substring("light.".Length)));
            }

            return(null);
        }