-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from Simnico99/design-time-theming
Design time theming
- Loading branch information
Showing
8 changed files
with
119 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <copyright file="DesignTimeHelper.cs" company="Zircon Technology"> | ||
// This software is distributed under the MIT license and its code is open-source and free for use, modification, and distribution. | ||
// </copyright> | ||
|
||
using System.ComponentModel; | ||
using System.Windows; | ||
|
||
namespace MicaWPF.Core.Helpers; | ||
|
||
public static class DesignTimeHelper | ||
{ | ||
public static bool IsDesignMode { get; } = DesignerProperties.GetIsInDesignMode(new DependencyObject()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// <copyright file="ThemeDictionaryBase.cs" company="Zircon Technology"> | ||
// This software is distributed under the MIT license and its code is open-source and free for use, modification, and distribution. | ||
// </copyright> | ||
|
||
using System.Windows; | ||
using System.Windows.Markup; | ||
using MicaWPF.Core.Enums; | ||
using MicaWPF.Core.Helpers; | ||
|
||
namespace MicaWPF.Core.Styles; | ||
|
||
[Localizability(LocalizationCategory.Ignore)] | ||
[UsableDuringInitialization(true)] | ||
public abstract class ThemeDictionaryBase : ResourceDictionary | ||
{ | ||
private WindowsTheme? _theme = null; | ||
private WindowsTheme? _designModeTheme = null; | ||
|
||
public ThemeDictionaryBase() | ||
{ | ||
if (DesignTimeHelper.IsDesignMode && !_designModeTheme.HasValue) | ||
{ | ||
SetTheme(WindowsTheme.Light); | ||
return; | ||
} | ||
|
||
if(!_theme.HasValue) | ||
{ | ||
SetTheme(WindowsTheme.Auto); | ||
} | ||
} | ||
|
||
public virtual string SourceLocation { get; } = string.Empty; | ||
|
||
public WindowsTheme Theme | ||
{ | ||
get => _theme!.Value; | ||
set | ||
{ | ||
_theme = value; | ||
if (!DesignTimeHelper.IsDesignMode) | ||
{ | ||
SetTheme(value); | ||
} | ||
} | ||
} | ||
|
||
public WindowsTheme DesignModeTheme | ||
{ | ||
get => _designModeTheme!.Value; | ||
set | ||
{ | ||
_designModeTheme = value; | ||
if (DesignTimeHelper.IsDesignMode) | ||
{ | ||
SetTheme(value); | ||
} | ||
} | ||
} | ||
|
||
protected void SetTheme(WindowsTheme value) | ||
{ | ||
var themeName = value switch | ||
{ | ||
WindowsTheme.Dark => "MicaDark", | ||
_ => "MicaLight", | ||
}; | ||
|
||
Source = new($"{SourceLocation}/{themeName}.xaml", UriKind.Absolute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters