mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-22 10:31:26 -07:00
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System.Windows;
|
|
using System.Windows.Interop;
|
|
using Wpf.Ui.Appearance;
|
|
using Wpf.Ui.Controls;
|
|
using Wpf.Ui.Mvvm.Contracts;
|
|
using Wpf.Ui.Mvvm.Services;
|
|
|
|
namespace Bloxstrap.UI.Elements.Base
|
|
{
|
|
public abstract class WpfUiWindow : UiWindow
|
|
{
|
|
private readonly IThemeService _themeService = new ThemeService();
|
|
|
|
public WpfUiWindow()
|
|
{
|
|
ApplyTheme();
|
|
}
|
|
|
|
public void ApplyTheme()
|
|
{
|
|
const int customThemeIndex = 2; // index for CustomTheme merged dictionary
|
|
|
|
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
|
|
_themeService.SetSystemAccent();
|
|
|
|
// there doesn't seem to be a way to query the name for merged dictionaries
|
|
var dict = new ResourceDictionary { Source = new Uri($"pack://application:,,,/UI/Style/{Enum.GetName(App.Settings.Prop.Theme.GetFinal())}.xaml") };
|
|
Application.Current.Resources.MergedDictionaries[customThemeIndex] = dict;
|
|
|
|
#if QA_BUILD
|
|
this.BorderBrush = System.Windows.Media.Brushes.Red;
|
|
this.BorderThickness = new Thickness(4);
|
|
#endif
|
|
}
|
|
|
|
protected override void OnSourceInitialized(EventArgs e)
|
|
{
|
|
if (App.Settings.Prop.WPFSoftwareRender || App.LaunchSettings.NoGPUFlag.Active)
|
|
{
|
|
if (PresentationSource.FromVisual(this) is HwndSource hwndSource)
|
|
hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
|
|
}
|
|
|
|
base.OnSourceInitialized(e);
|
|
}
|
|
}
|
|
}
|