Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CPAP-Exporter.UI/CpapExporterThemeDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Windows;

namespace CascadePass.CPAPExporter
{
public class CpapExporterThemeDetector : ThemeDetector
{
public CpapExporterThemeDetector() : base()
{
}

public CpapExporterThemeDetector(IRegistryProvider registryProviderToUse) : base(registryProviderToUse)
{
}

public override bool ApplyTheme()
{
if (Application.Current?.Dispatcher is null)
{
// This is probably a unit test.
return false;
}

Application.Current.Dispatcher.Invoke(() =>
{

Application.Current.Resources.MergedDictionaries.Clear();

var currentTheme = this.GetThemeType();
if (currentTheme == ThemeType.Dark)
{
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Themes/Dark.xaml", UriKind.Relative) });
}
else if (currentTheme == ThemeType.Light)
{
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Themes/Light.xaml", UriKind.Relative) });
}

Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Fonts.xaml", UriKind.Relative) });
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Styles.xaml", UriKind.Relative) });

Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml", UriKind.Absolute) });
});

return true;
}
}
}
41 changes: 0 additions & 41 deletions CPAP-Exporter.UI/ThemeDetector.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CascadePass.CPAPExporter
Expand Down Expand Up @@ -94,42 +89,6 @@ protected async void OnThemeChanged(object sender, EventArgs e)
#endregion
}

public class CpapExporterThemeDetector : ThemeDetector
{
public CpapExporterThemeDetector() : base()
{
}

public CpapExporterThemeDetector(IRegistryProvider registryProviderToUse) : base(registryProviderToUse)
{
}

public override bool ApplyTheme()
{
// Implement the logic to apply the theme based on the current system settings.

Application.Current.Resources.MergedDictionaries.Clear();

var currentTheme = this.GetThemeType();
if (currentTheme == ThemeType.Dark)
{
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Themes/Dark.xaml", UriKind.Relative) });
}
else if (currentTheme == ThemeType.Light)
{
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Themes/Light.xaml", UriKind.Relative) });
}

Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Fonts.xaml", UriKind.Relative) });
Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("/Styles.xaml", UriKind.Relative) });

Application.Current.Resources.MergedDictionaries.Add(new() { Source = new Uri("pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml", UriKind.Absolute) });
//base.ThemeChanged?.Invoke(this, EventArgs.Empty);

return true;
}
}

/// <summary>
/// Represents a type or category of theme, of which there can be many individual
/// themes. Applications typically implement their own themes, sometimes many;
Expand Down
Loading