mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
real time refresh background
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Message;
|
||||
|
||||
internal sealed class BackgroundImageTypeChangedMessage
|
||||
{
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
<mxi:Interaction.Behaviors>
|
||||
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
||||
Command="{Binding UpdateBackgroundCommand}"
|
||||
CommandParameter="{x:Bind BackdroundImagePresenter}"
|
||||
CommandParameter="{x:Bind BackgroundImagePresenter}"
|
||||
Period="0:5:0"/>
|
||||
</mxi:Interaction.Behaviors>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<!-- Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" -->
|
||||
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||
<Image
|
||||
x:Name="BackdroundImagePresenter"
|
||||
x:Name="BackgroundImagePresenter"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Opacity="0"
|
||||
|
||||
@@ -27,10 +27,14 @@ internal sealed partial class MainView : UserControl
|
||||
/// </summary>
|
||||
public MainView()
|
||||
{
|
||||
DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
|
||||
IServiceProvider serviceProvider = Ioc.Default;
|
||||
|
||||
MainViewModel mainViewModel = serviceProvider.GetRequiredService<MainViewModel>();
|
||||
|
||||
DataContext = mainViewModel;
|
||||
InitializeComponent();
|
||||
|
||||
IServiceProvider serviceProvider = Ioc.Default;
|
||||
mainViewModel.Initialize(BackgroundImagePresenter);
|
||||
|
||||
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
||||
if (navigationService is INavigationInitialization navigationInitialization)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Snap.Hutao.ViewModel.Main;
|
||||
|
||||
internal interface IMainViewModelInitialization
|
||||
{
|
||||
void Initialize(Image backgroundImagePresenter);
|
||||
}
|
||||
@@ -1,23 +1,37 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI.Animations;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Snap.Hutao.Control.Animation;
|
||||
using Snap.Hutao.Control.Theme;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
using Snap.Hutao.ViewModel.Main;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class MainViewModel : Abstraction.ViewModel
|
||||
internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewModelInitialization, IRecipient<BackgroundImageTypeChangedMessage>
|
||||
{
|
||||
private readonly IBackgroundImageService backgroundImageService;
|
||||
private readonly ITaskContext taskContext;
|
||||
|
||||
private BackgroundImage? previousBackgroundImage;
|
||||
private Image backgroundImagePresenter;
|
||||
|
||||
public void Initialize(Image backgroundImagePresenter)
|
||||
{
|
||||
this.backgroundImagePresenter = backgroundImagePresenter;
|
||||
}
|
||||
|
||||
public void Receive(BackgroundImageTypeChangedMessage message)
|
||||
{
|
||||
UpdateBackgroundAsync(backgroundImagePresenter).SafeForget();
|
||||
}
|
||||
|
||||
[Command("UpdateBackgroundCommand")]
|
||||
private async Task UpdateBackgroundAsync(Image presenter)
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.Windows.AppLifecycle;
|
||||
using Snap.Hutao.Core;
|
||||
@@ -54,6 +55,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
private readonly IUserService userService;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly AppOptions appOptions;
|
||||
private readonly IMessenger messenger;
|
||||
|
||||
private NameValue<BackdropType>? selectedBackdropType;
|
||||
private NameValue<BackgroundImageType>? selectedBackgroundImageType;
|
||||
@@ -100,6 +102,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
if (SetProperty(ref selectedBackgroundImageType, value) && value is not null)
|
||||
{
|
||||
AppOptions.BackgroundImageType = value.Value;
|
||||
messenger.Send(new Message.BackgroundImageTypeChangedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user