From 902c2991eca246e0f1bda15d52220701e03c14b3 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Tue, 12 May 2026 14:36:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BE=E6=89=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyUserControl/CoverFlowControl.xaml.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs index 465ebb8..6cb5175 100644 --- a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs +++ b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml.cs @@ -24,6 +24,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl private const double CardHeight = 534; private const double CardGap = 30; // 卡片之间水平间距 private const double SlideDurationMs = 380; // 动画时长 + private const double ProgressDurationMs = 2600; public int SelectedIndex { @@ -65,6 +66,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl private EventHandler? _renderHandler; private CoverFlowItem? _currentItem; + private DateTime _progressStartTime; private void CoverFlowControl_Loaded(object sender, RoutedEventArgs e) { @@ -97,7 +99,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl var current = Images[SelectedIndex]; // 停止动画/计时 - StopProgress(); + StopProgress(resetProgress: true); // 清零当前的进度值 current.Progress = 0; @@ -105,29 +107,33 @@ namespace Wpf_AiSportsMicrospace.MyUserControl } public void StartProgress(CoverFlowItem item) { - StopProgress(); + StopProgress(resetProgress: true); _currentItem = item; item.Progress = 0; + _progressStartTime = DateTime.UtcNow; _renderHandler = (s, e) => { - if (_currentItem.Progress < 1) - { - _currentItem.Progress += 0.007; // 控制速度 - } - else + if (_currentItem == null) + return; + + var elapsedMs = (DateTime.UtcNow - _progressStartTime).TotalMilliseconds; + _currentItem.Progress = Math.Min(1, elapsedMs / ProgressDurationMs); + + if (_currentItem.Progress >= 1) { + _currentItem.Progress = 1; ProgressCompleted?.Invoke(_currentItem); // 停止动画 - StopProgress(); + StopProgress(resetProgress: false); } }; CompositionTarget.Rendering += _renderHandler; } - private void StopProgress() + private void StopProgress(bool resetProgress = true) { if (_renderHandler != null) @@ -138,7 +144,9 @@ namespace Wpf_AiSportsMicrospace.MyUserControl if (_currentItem != null) { - _currentItem.Progress = 0; + if (resetProgress) + _currentItem.Progress = 0; + _currentItem = null; } }