更新全屏RootPlayBar隐藏

This commit is contained in:
LanZhan
2026-03-13 01:35:49 +08:00
parent d41a99ff8a
commit e63dbe7cbc
4 changed files with 245 additions and 7 deletions

View File

@@ -12,8 +12,26 @@
PersistenceId="MainWindow"
mc:Ignorable="d">
<Grid x:Name="RootGrid">
<Grid x:Name="RootGrid" Background="Transparent">
<Grid.Resources>
<Storyboard x:Name="ShowPlayBarStoryboard">
<DoubleAnimation Storyboard.TargetName="RootPlayBar"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="117" To="0"
Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetName="RootPlayBar"
Storyboard.TargetProperty="Opacity" From="0"
To="1" Duration="0:0:0.2"/>
</Storyboard>
<Storyboard x:Name="HidePlayBarStoryboard">
<DoubleAnimation Storyboard.TargetName="RootPlayBar"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="0" To="117"
Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetName="RootPlayBar"
Storyboard.TargetProperty="Opacity" From="1"
To="0" Duration="0:0:0.2"/>
</Storyboard>
<Storyboard x:Name="ShowInfoBarStoryboard">
<DoubleAnimation Storyboard.TargetName="ErrorInfoBar"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
@@ -35,13 +53,14 @@
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="117"/>
<RowDefinition x:Name="PlayBarRow" Height="117"/>
</Grid.RowDefinitions>
<Grid x:Name="BackgroundGrid"
Grid.Row="0" Grid.RowSpan="2"
Canvas.ZIndex="0"/>
<Frame x:Name="ShellFrame"
Grid.Row="0"
Grid.Row="0" Grid.RowSpan="2"
Margin="0,0,0,117"
Canvas.ZIndex="1"/>
<Border x:Name="ShadowTarget"/>
<InfoBar x:Name="ErrorInfoBar"
@@ -63,6 +82,12 @@
<CompositeTransform/>
</InfoBar.RenderTransform>
</InfoBar>
<view:RootPlayBarView Grid.Row="1" Canvas.ZIndex="1"/>
<view:RootPlayBarView x:Name="RootPlayBar"
Grid.Row="1"
Canvas.ZIndex="1">
<view:RootPlayBarView.RenderTransform>
<CompositeTransform/>
</view:RootPlayBarView.RenderTransform>
</view:RootPlayBarView>
</Grid>
</windowex:WindowEx>

View File

@@ -1,3 +1,4 @@
using System.ComponentModel;
using System.Numerics;
using System.Runtime.InteropServices;
using CommunityToolkit.Mvvm.Messaging;
@@ -12,6 +13,7 @@ using UntamedMusicPlayer.Helpers;
using UntamedMusicPlayer.Messages;
using UntamedMusicPlayer.Models;
using UntamedMusicPlayer.Services;
using UntamedMusicPlayer.ViewModels;
using UntamedMusicPlayer.Views;
using Windows.System;
using WinRT.Interop;
@@ -25,6 +27,9 @@ public sealed partial class MainWindow : WindowEx, IRecipient<LogMessage>
private readonly ILogger _logger = LoggingService.CreateLogger<MainWindow>();
private readonly InfoBarManager? _infoBarManager;
private bool _isClosingWorkDone;
private readonly Timer _playBarTimer;
private bool _playBarTimerEnabled = false;
private bool _isPlayBarHidden = false;
// 热键 ID
private const int HOTKEY_ID_VOLUME_UP = 1;
@@ -80,6 +85,98 @@ public sealed partial class MainWindow : WindowEx, IRecipient<LogMessage>
// 注册系统级全局热键
Activated += MainWindow_Activated;
// 初始化播放栏隐藏定时器
_playBarTimer = new Timer(TimerTick, null, Timeout.Infinite, Timeout.Infinite);
Data.RootPlayBarViewModel?.PropertyChanged += RootPlayBarViewModelPropertyChanged;
}
private void RootPlayBarViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (
e.PropertyName
is nameof(RootPlayBarViewModel.IsDetail)
or nameof(RootPlayBarViewModel.IsFullScreen)
)
{
if (Data.RootPlayBarViewModel!.IsDetail && Data.RootPlayBarViewModel.IsFullScreen)
{
RootGrid.PointerMoved += RootGrid_PointerMoved;
}
else
{
RootGrid.PointerMoved -= RootGrid_PointerMoved;
if (_isPlayBarHidden)
{
ShellFrame.Margin = new Thickness(0, 0, 0, 117);
ShowPlayBarStoryboard.Begin();
_isPlayBarHidden = false;
StopPlayBarTimer();
}
}
}
}
private void RootGrid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var pointerPoint = e.GetCurrentPoint(RootGrid);
var position = pointerPoint.Position;
var height = RootGrid.ActualHeight;
if (position.Y > height - 117) // 如果鼠标在底部 117 像素范围内
{
ShellFrame.Margin = new Thickness(0, 0, 0, 117);
if (_isPlayBarHidden)
{
ShowPlayBarStoryboard.Begin();
_isPlayBarHidden = false;
}
StopPlayBarTimer();
}
else if (!_isPlayBarHidden) // 鼠标离开了底部,开始定时器
{
StartPlayBarTimer();
}
}
private void TimerTick(object? state)
{
StopPlayBarTimer();
DispatcherQueue.TryEnqueue(
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low,
() =>
{
if (
Data.RootPlayBarViewModel!.IsDetail
&& Data.RootPlayBarViewModel.IsFullScreen
&& !_isPlayBarHidden
)
{
ShellFrame.Margin = new Thickness(0);
HidePlayBarStoryboard.Begin();
_isPlayBarHidden = true;
}
}
);
}
private void StartPlayBarTimer()
{
if (!_playBarTimerEnabled)
{
_playBarTimer.Change(TimeSpan.FromSeconds(2), Timeout.InfiniteTimeSpan);
_playBarTimerEnabled = true;
}
}
private void StopPlayBarTimer()
{
if (_playBarTimerEnabled)
{
_playBarTimer.Change(Timeout.Infinite, Timeout.Infinite);
_playBarTimerEnabled = false;
}
}
/// <summary>
@@ -317,6 +414,7 @@ public sealed partial class MainWindow : WindowEx, IRecipient<LogMessage>
App.GetService<IMaterialSelectorService>().Dispose();
App.GetService<IDynamicBackgroundService>().Dispose();
_playBarTimer?.Dispose();
}
catch (Exception ex)
{

View File

@@ -51,12 +51,29 @@
</Grid>
</UserControl>
</DataTemplate>
<Storyboard x:Name="ShowTitleBarStoryboard">
<DoubleAnimation Storyboard.TargetName="AppTitleBar"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="-33" To="0"
Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetName="AppTitleBar"
Storyboard.TargetProperty="Opacity" From="0"
To="1" Duration="0:0:0.2"/>
</Storyboard>
<Storyboard x:Name="HideTitleBarStoryboard">
<DoubleAnimation Storyboard.TargetName="AppTitleBar"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="0" To="-33"
Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetName="AppTitleBar"
Storyboard.TargetProperty="Opacity" From="1"
To="0" Duration="0:0:0.2"/>
</Storyboard>
</Page.Resources>
<Grid>
<Grid x:Name="RootGrid" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="33"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
@@ -114,6 +131,9 @@
Height="33"
VerticalAlignment="Center"
Canvas.ZIndex="1" IsHitTestVisible="True">
<Grid.RenderTransform>
<CompositeTransform/>
</Grid.RenderTransform>
<StackPanel Orientation="Horizontal">
<Button Width="48" Height="39"
AccessKey="A" Click="CoverBtnClickToDetail"

View File

@@ -2,6 +2,7 @@ using System.ComponentModel;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using UntamedMusicPlayer.Controls;
using UntamedMusicPlayer.Models;
using UntamedMusicPlayer.Playback;
@@ -18,6 +19,10 @@ public sealed partial class LyricPage : Page, IDisposable
private bool _isManualScrolling;
private bool _isProgrammaticScroll;
private readonly Timer _titleBarTimer;
private bool _titleBarTimerEnabled = false;
private bool _isTitleBarHidden = false;
public LyricPage()
{
ViewModel = App.GetService<LyricViewModel>();
@@ -31,6 +36,96 @@ public sealed partial class LyricPage : Page, IDisposable
Timeout.Infinite,
Timeout.Infinite
);
_titleBarTimer = new Timer(TimerTick, null, Timeout.Infinite, Timeout.Infinite);
Data.RootPlayBarViewModel?.PropertyChanged += RootPlayBarViewModelPropertyChanged;
}
private void RootPlayBarViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (
e.PropertyName
is nameof(RootPlayBarViewModel.IsDetail)
or nameof(RootPlayBarViewModel.IsFullScreen)
)
{
if (Data.RootPlayBarViewModel!.IsDetail && Data.RootPlayBarViewModel.IsFullScreen)
{
RootGrid.PointerMoved += RootGrid_PointerMoved;
}
else
{
RootGrid.PointerMoved -= RootGrid_PointerMoved;
if (_isTitleBarHidden)
{
ContentGrid.Margin = new Thickness(0);
ShowTitleBarStoryboard.Begin();
_isTitleBarHidden = false;
StopTitleBarTimer();
}
}
}
}
private void RootGrid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var pointerPoint = e.GetCurrentPoint(RootGrid);
var position = pointerPoint.Position;
if (position.Y < 33) // 如果鼠标在顶部 33 像素范围内
{
if (_isTitleBarHidden)
{
ContentGrid.Margin = new Thickness(0);
ShowTitleBarStoryboard.Begin();
_isTitleBarHidden = false;
}
StopTitleBarTimer();
}
else if (!_isTitleBarHidden) // 鼠标离开了底部,开始定时器
{
StartTitleBarTimer();
}
}
private void TimerTick(object? state)
{
StopTitleBarTimer();
DispatcherQueue.TryEnqueue(
DispatcherQueuePriority.Low,
() =>
{
if (
Data.RootPlayBarViewModel!.IsDetail
&& Data.RootPlayBarViewModel.IsFullScreen
&& !_isTitleBarHidden
)
{
ContentGrid.Margin = new Thickness(0, -33, 0, 0);
HideTitleBarStoryboard.Begin();
_isTitleBarHidden = true;
}
}
);
}
private void StartTitleBarTimer()
{
if (!_titleBarTimerEnabled)
{
_titleBarTimer.Change(TimeSpan.FromSeconds(2), Timeout.InfiniteTimeSpan);
_titleBarTimerEnabled = true;
}
}
private void StopTitleBarTimer()
{
if (_titleBarTimerEnabled)
{
_titleBarTimer.Change(Timeout.Infinite, Timeout.Infinite);
_titleBarTimerEnabled = false;
}
}
private void CoverBtnClickToDetail(object sender, RoutedEventArgs e)