Skip to content

Commit a8057a3

Browse files
committed
Add utility method to check for dark mode
1 parent 39c72a2 commit a8057a3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/ThemeDialog.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public ThemeDialog()
3333
Localization.TranslateForm(this);
3434
this.themeLinkLabel.Left += (this.importButton.Width - oldButtonWidth);
3535

36-
#pragma warning disable SYSLIB5002
37-
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
36+
this.searchBoxButton.BackgroundImage = UwpDesktop.IsDarkMode() ?
3837
Resources.IconSearch_Dark : Resources.IconSearch_Light;
39-
#pragma warning restore SYSLIB5002
4038
this.themeLinkLabel.LinkColor = SystemColors.HotTrack;
4139

4240
this.FormClosing += OnFormClosing;
@@ -268,18 +266,16 @@ private void ThemeDialog_Load(object sender, EventArgs e)
268266

269267
private void searchBox_TextChanged(object sender, EventArgs e)
270268
{
271-
#pragma warning disable SYSLIB5002
272269
if (string.IsNullOrWhiteSpace(searchBox.Text))
273270
{
274-
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
271+
this.searchBoxButton.BackgroundImage = UwpDesktop.IsDarkMode() ?
275272
Resources.IconSearch_Dark : Resources.IconSearch_Light;
276273
}
277274
else
278275
{
279-
this.searchBoxButton.BackgroundImage = SystemColors.UseAlternativeColorSet ?
276+
this.searchBoxButton.BackgroundImage = UwpDesktop.IsDarkMode() ?
280277
Resources.IconDismiss_Dark : Resources.IconDismiss_Light;
281278
}
282-
#pragma warning restore SYSLIB5002
283279

284280
ThemeDialogUtils.ApplySearchFilter(listView1, searchBox.Text);
285281
UpdateSelectedItem();

src/UwpDesktop.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class UwpDesktop
2727
private static bool? _isRunningAsUwp;
2828
private static PlatformHelper helper;
2929

30+
public static bool IsDarkMode()
31+
{
32+
#pragma warning disable SYSLIB5002
33+
return System.Drawing.SystemColors.UseAlternativeColorSet;
34+
#pragma warning restore SYSLIB5002
35+
}
36+
3037
public static bool IsRunningAsUwp()
3138
{
3239
if (!_isRunningAsUwp.HasValue)

0 commit comments

Comments
 (0)