Skip to content

Commit

Permalink
RequestedTheme.Default had no effect. Fixes #101
Browse files Browse the repository at this point in the history
  • Loading branch information
dotMorten committed Apr 13, 2023
1 parent 4905982 commit 13085d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/WinUIEx/WinUIEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<PackageId>WinUIEx</PackageId>
<Product>WinUI Extensions</Product>
<PackageReleaseNotes>
- Upgrade to Windows App SDK 1.3
- Deprecated Backdrop APIs in favor of Microsoft's new Backdrop APIs
- Upgrade to Windows App SDK 1.3.
- Deprecated Backdrop APIs in favor of Microsoft's new Backdrop APIs.
- Setting Default RequestedTheme has no effect (Issue #101)
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
22 changes: 16 additions & 6 deletions src/WinUIEx/WindowEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,28 @@ public object? WindowContent
{
get => windowArea.Content;
set
{
if(windowArea.Content is FrameworkElement oldelm)
oldelm.ActualThemeChanged -= WindowContent_ActualThemeChanged;
{
if (windowArea.Content is FrameworkElement oldelm)
{
if (_propChangedCallbackId != 0)
{
oldelm.UnregisterPropertyChangedCallback(FrameworkElement.RequestedThemeProperty, _propChangedCallbackId);
_propChangedCallbackId = 0;
}
}
windowArea.Content = value;
if (windowArea.Content is FrameworkElement newelm)
newelm.ActualThemeChanged += WindowContent_ActualThemeChanged;
{
_propChangedCallbackId = newelm.RegisterPropertyChangedCallback(FrameworkElement.RequestedThemeProperty, RequestedThemePropertyChanged);
}
}
}

private void WindowContent_ActualThemeChanged(FrameworkElement sender, object args)
private long _propChangedCallbackId;

private void RequestedThemePropertyChanged(DependencyObject sender, DependencyProperty dp)
{
if(this.Content is FrameworkElement elm && windowArea.Content is FrameworkElement childelm)
if (this.Content is FrameworkElement elm && windowArea.Content is FrameworkElement childelm)
{
elm.RequestedTheme = childelm.RequestedTheme;
}
Expand Down

0 comments on commit 13085d2

Please sign in to comment.