mirror of
https://github.com/Pixeval/Pixeval.git
synced 2025-01-08 11:47:34 +08:00
修复主题色问题 (#413)
This commit is contained in:
parent
29c9ec50c0
commit
a2730e1509
@ -22,7 +22,7 @@
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240328-rc" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.1.240328-rc" />
|
||||
<PackageReference Include="WinUI3Utilities" Version="1.1.6.3" />
|
||||
<PackageReference Include="WinUI3Utilities" Version="1.1.6.5" />
|
||||
|
||||
<ProjectReference Include="..\Pixeval.Utilities\Pixeval.Utilities.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -23,15 +23,12 @@ using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Windows.Foundation;
|
||||
using Windows.Graphics;
|
||||
using Microsoft.UI;
|
||||
using WinUI3Utilities;
|
||||
|
||||
namespace Pixeval.Controls.Windowing;
|
||||
|
||||
public static class WindowFactory
|
||||
{
|
||||
public static bool IsDarkMode { get; private set; }
|
||||
|
||||
public static string IconAbsolutePath { get; set; } = "";
|
||||
|
||||
public static IWindowSettings WindowSettings { get; set; } = null!;
|
||||
@ -44,8 +41,14 @@ public static class WindowFactory
|
||||
|
||||
public static void Initialize(IWindowSettings windowSettings, string iconAbsolutePath)
|
||||
{
|
||||
IsDarkMode = Application.Current.RequestedTheme is ApplicationTheme.Dark;
|
||||
AppHelper.InitializeIsDarkMode();
|
||||
WindowSettings = windowSettings;
|
||||
Application.Current.RequestedTheme = WindowSettings.Theme switch
|
||||
{
|
||||
ElementTheme.Light => ApplicationTheme.Light,
|
||||
ElementTheme.Dark => ApplicationTheme.Dark,
|
||||
_ => Application.Current.RequestedTheme
|
||||
};
|
||||
IconAbsolutePath = iconAbsolutePath;
|
||||
}
|
||||
|
||||
@ -107,43 +110,25 @@ public static class WindowFactory
|
||||
ExtendTitleBar = true,
|
||||
Size = size,
|
||||
IconPath = IconAbsolutePath,
|
||||
Title = title
|
||||
Title = title,
|
||||
IsMaximized = isMaximized,
|
||||
Theme = WindowSettings.Theme
|
||||
});
|
||||
if (isMaximized)
|
||||
window.AppWindow.Presenter.To<OverlappedPresenter>().Maximize();
|
||||
window.FrameLoaded += (_, _) => SetTheme(window, WindowSettings.Theme);
|
||||
window.FrameLoaded += (_, _) => window.SetTheme(WindowSettings.Theme);
|
||||
return window;
|
||||
}
|
||||
|
||||
public static void SetBackdrop(BackdropType backdropType)
|
||||
{
|
||||
foreach (var window in _forkedWindowsInternal)
|
||||
foreach (var window in _forkedWindowsInternal)
|
||||
window.SetBackdrop(backdropType);
|
||||
}
|
||||
|
||||
public static void SetTheme(ElementTheme theme)
|
||||
{
|
||||
foreach (var window in _forkedWindowsInternal)
|
||||
SetTheme(window, theme);
|
||||
}
|
||||
|
||||
public static void SetTheme(EnhancedWindow window, ElementTheme theme)
|
||||
{
|
||||
var actualTheme = theme switch
|
||||
{
|
||||
ElementTheme.Default => IsDarkMode ? ElementTheme.Dark : ElementTheme.Light,
|
||||
_ => theme
|
||||
};
|
||||
window.Content.To<FrameworkElement>().RequestedTheme = actualTheme;
|
||||
|
||||
var color = actualTheme switch
|
||||
{
|
||||
ElementTheme.Dark => Colors.White,
|
||||
_ => Colors.Black,
|
||||
};
|
||||
|
||||
var res = Application.Current.Resources;
|
||||
res["WindowCaptionForeground"] = color;
|
||||
window.AppWindow.TitleBar.ButtonForegroundColor = color;
|
||||
window.SetTheme(theme);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ using Pixeval.Pages.Login;
|
||||
using WinUI3Utilities;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Windows.ApplicationModel.Resources;
|
||||
using Pixeval.Logging;
|
||||
using Pixeval.Util.UI;
|
||||
using Pixeval.Utilities;
|
||||
|
@ -58,7 +58,7 @@
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.2" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
<PackageReference Include="WinUI3Utilities" Version="1.1.6.3" />
|
||||
<PackageReference Include="WinUI3Utilities" Version="1.1.6.5" />
|
||||
|
||||
<ProjectReference Include="..\Pixeval.Controls\Pixeval.Controls.csproj" />
|
||||
<ProjectReference Include="..\Pixeval.CoreApi\Pixeval.CoreApi.csproj" />
|
||||
|
@ -254,40 +254,9 @@ public static partial class UiHelper
|
||||
box.Document.SetText(TextSetOptions.None, "");
|
||||
}
|
||||
|
||||
public static IAsyncOperation<StorageFolder?> OpenFolderPickerAsync(this Window window)
|
||||
{
|
||||
var folderPicker = new FolderPicker
|
||||
{
|
||||
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
|
||||
FileTypeFilter = { "*" }
|
||||
};
|
||||
return folderPicker.InitializeWithWindow(window).PickSingleFolderAsync();
|
||||
}
|
||||
public static IAsyncOperation<StorageFolder?> OpenFolderPickerAsync(this Window window) => window.PickSingleFolderAsync(PickerLocationId.PicturesLibrary);
|
||||
|
||||
public static IAsyncOperation<StorageFile?> OpenFileSavePickerAsync(this Window window, string suggestedFileName, string fileTypeId)
|
||||
{
|
||||
var savePicker = new FileSavePicker
|
||||
{
|
||||
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
|
||||
FileTypeChoices =
|
||||
{
|
||||
[fileTypeId] = [fileTypeId]
|
||||
},
|
||||
SuggestedFileName = suggestedFileName
|
||||
};
|
||||
return savePicker.InitializeWithWindow(window).PickSaveFileAsync();
|
||||
}
|
||||
|
||||
public static IAsyncOperation<StorageFile?> OpenFileOpenPickerAsync(this Window window)
|
||||
{
|
||||
var openPicker = new FileOpenPicker
|
||||
{
|
||||
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
|
||||
ViewMode = PickerViewMode.Thumbnail,
|
||||
FileTypeFilter = { "*" }
|
||||
};
|
||||
return openPicker.InitializeWithWindow(window).PickSingleFileAsync();
|
||||
}
|
||||
public static IAsyncOperation<StorageFile?> OpenFileOpenPickerAsync(this Window window) => window.PickSingleFileAsync(PickerLocationId.PicturesLibrary);
|
||||
|
||||
public static async Task<T> AwaitPageTransitionAsync<T>(this Frame root) where T : Page
|
||||
{
|
||||
|
@ -268,9 +268,9 @@
|
||||
},
|
||||
"WinUI3Utilities": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.1.6.3, )",
|
||||
"resolved": "1.1.6.3",
|
||||
"contentHash": "tloZd//pw5fujNIT1UdKqszTN53YrzyqhtBb6ZcOcZBN8tpPtlONE/OKoj/OABwSgUuJj8090DMr+dLP7BlGsw==",
|
||||
"requested": "[1.1.6.5, )",
|
||||
"resolved": "1.1.6.5",
|
||||
"contentHash": "ug/bvu2PiIoRNlO1g3hHsJbfp6vmOh3RIUaczUZpCNG4TCYbrqh8Nkohw/JZuG+NNPybuKfGJrrc6WRaLALkRQ==",
|
||||
"dependencies": {
|
||||
"Microsoft.Windows.SDK.BuildTools": "10.0.22621.3233",
|
||||
"Microsoft.WindowsAppSDK": "1.5.240311000"
|
||||
@ -452,7 +452,7 @@
|
||||
"Microsoft.WindowsAppSDK": "[1.5.240311000, )",
|
||||
"Microsoft.Xaml.Behaviors.WinUI.Managed": "[2.0.9, )",
|
||||
"Pixeval.Utilities": "[1.0.0, )",
|
||||
"WinUI3Utilities": "[1.1.6.3, )"
|
||||
"WinUI3Utilities": "[1.1.6.5, )"
|
||||
}
|
||||
},
|
||||
"pixeval.coreapi": {
|
||||
|
Loading…
Reference in New Issue
Block a user