Skip to content

Commit

Permalink
Fix theme not applying to notification area menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Aug 26, 2023
1 parent 0cca373 commit 197429d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
24 changes: 24 additions & 0 deletions Bloxstrap/UI/Elements/Base/WpfUiWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;

namespace Bloxstrap.UI.Elements.Base
{
public class WpfUiWindow : UiWindow
{
private readonly IThemeService _themeService = new ThemeService();

public void ApplyTheme()
{
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent();
}
}
}
5 changes: 3 additions & 2 deletions Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.Bootstrapper.FluentDialog"
<base:WpfUiWindow x:Class="Bloxstrap.UI.Elements.Bootstrapper.FluentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:base="clr-namespace:Bloxstrap.UI.Elements.Base"
mc:Ignorable="d"
Width="420"
MinHeight="0"
Expand Down Expand Up @@ -46,4 +47,4 @@
<Button Margin="0" Content="Cancel" Width="120" HorizontalAlignment="Right" IsEnabled="{Binding CancelEnabled, Mode=OneWay}" Command="{Binding CancelInstallCommand}" />
</Border>
</Grid>
</ui:UiWindow>
</base:WpfUiWindow>
10 changes: 3 additions & 7 deletions Bloxstrap/UI/Elements/Bootstrapper/FluentDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
/// </summary>
public partial class FluentDialog : IBootstrapperDialog
{
private readonly IThemeService _themeService = new ThemeService();

private readonly BootstrapperDialogViewModel _viewModel;

public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }
Expand Down Expand Up @@ -69,15 +67,13 @@ public bool CancelEnabled

public FluentDialog()
{
InitializeComponent();
ApplyTheme();

_viewModel = new FluentDialogViewModel(this);
DataContext = _viewModel;
Title = App.Settings.Prop.BootstrapperTitle;
Icon = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource();

_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent();

InitializeComponent();
}

private void UiWindow_Closing(object sender, CancelEventArgs e)
Expand Down
5 changes: 3 additions & 2 deletions Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.ContextMenu.MenuContainer"
<base:WpfUiWindow x:Class="Bloxstrap.UI.Elements.ContextMenu.MenuContainer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.ContextMenu"
xmlns:base="clr-namespace:Bloxstrap.UI.Elements.Base"
mc:Ignorable="d"
Title="ContextMenuContainer"
MinWidth="0"
Expand Down Expand Up @@ -62,4 +63,4 @@
<MenuItem x:Name="LogTracerMenuItem" Header="Open log tracer" Visibility="Collapsed" Click="LogTracerMenuItem_Click" />
</ContextMenu>
</ui:UiWindow.ContextMenu>
</ui:UiWindow>
</base:WpfUiWindow>
7 changes: 6 additions & 1 deletion Bloxstrap/UI/Elements/ContextMenu/MenuContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using System.Windows.Controls;
using System.Windows.Interop;

using Wpf.Ui.Appearance;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;

using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;
Expand All @@ -26,7 +30,8 @@ public partial class MenuContainer
public MenuContainer(ActivityWatcher? activityWatcher, DiscordRichPresence? richPresenceHandler)
{
InitializeComponent();

ApplyTheme();

_activityWatcher = activityWatcher;
_richPresenceHandler = richPresenceHandler;

Expand Down
5 changes: 3 additions & 2 deletions Bloxstrap/UI/Elements/Menu/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.Menu.MainWindow"
<base:WpfUiWindow x:Class="Bloxstrap.UI.Elements.Menu.MainWindow"
x:Name="ConfigurationWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:Bloxstrap.UI.Elements.Menu.Pages"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:base="clr-namespace:Bloxstrap.UI.Elements.Base"
mc:Ignorable="d"
Title="Bloxstrap Menu"
MinWidth="960"
Expand Down Expand Up @@ -79,4 +80,4 @@
</StatusBarItem>
</StatusBar>
</Grid>
</ui:UiWindow>
</base:WpfUiWindow>
13 changes: 3 additions & 10 deletions Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ namespace Bloxstrap.UI.Elements.Menu
/// </summary>
public partial class MainWindow : INavigationWindow
{
private readonly IThemeService _themeService = new ThemeService();

public MainWindow()
{
InitializeComponent();
ApplyTheme();

App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu");

DataContext = new MainWindowViewModel(this);
SetTheme();
InitializeComponent();
}

public void SetTheme()
{
_themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light);
_themeService.SetSystemAccent();
}

public void OpenWiki(object? sender, EventArgs e) => Utilities.ShellExecute($"https://github.com/{App.ProjectRepository}/wiki");
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/ViewModels/Menu/AppearanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public string Theme
set
{
App.Settings.Prop.Theme = Themes[value];
((MainWindow)Window.GetWindow(_page)!).SetTheme();
((MainWindow)Window.GetWindow(_page)!).ApplyTheme();
}
}

Expand Down

0 comments on commit 197429d

Please sign in to comment.