举手优化
This commit is contained in:
parent
cb5286163c
commit
902c2991ec
@ -24,6 +24,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
private const double CardHeight = 534;
|
private const double CardHeight = 534;
|
||||||
private const double CardGap = 30; // 卡片之间水平间距
|
private const double CardGap = 30; // 卡片之间水平间距
|
||||||
private const double SlideDurationMs = 380; // 动画时长
|
private const double SlideDurationMs = 380; // 动画时长
|
||||||
|
private const double ProgressDurationMs = 2600;
|
||||||
|
|
||||||
public int SelectedIndex
|
public int SelectedIndex
|
||||||
{
|
{
|
||||||
@ -65,6 +66,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
private EventHandler? _renderHandler;
|
private EventHandler? _renderHandler;
|
||||||
|
|
||||||
private CoverFlowItem? _currentItem;
|
private CoverFlowItem? _currentItem;
|
||||||
|
private DateTime _progressStartTime;
|
||||||
|
|
||||||
private void CoverFlowControl_Loaded(object sender, RoutedEventArgs e)
|
private void CoverFlowControl_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
@ -97,7 +99,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
var current = Images[SelectedIndex];
|
var current = Images[SelectedIndex];
|
||||||
|
|
||||||
// 停止动画/计时
|
// 停止动画/计时
|
||||||
StopProgress();
|
StopProgress(resetProgress: true);
|
||||||
|
|
||||||
// 清零当前的进度值
|
// 清零当前的进度值
|
||||||
current.Progress = 0;
|
current.Progress = 0;
|
||||||
@ -105,29 +107,33 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
}
|
}
|
||||||
public void StartProgress(CoverFlowItem item)
|
public void StartProgress(CoverFlowItem item)
|
||||||
{
|
{
|
||||||
StopProgress();
|
StopProgress(resetProgress: true);
|
||||||
|
|
||||||
_currentItem = item;
|
_currentItem = item;
|
||||||
item.Progress = 0;
|
item.Progress = 0;
|
||||||
|
_progressStartTime = DateTime.UtcNow;
|
||||||
|
|
||||||
_renderHandler = (s, e) =>
|
_renderHandler = (s, e) =>
|
||||||
{
|
{
|
||||||
if (_currentItem.Progress < 1)
|
if (_currentItem == null)
|
||||||
{
|
return;
|
||||||
_currentItem.Progress += 0.007; // 控制速度
|
|
||||||
}
|
var elapsedMs = (DateTime.UtcNow - _progressStartTime).TotalMilliseconds;
|
||||||
else
|
_currentItem.Progress = Math.Min(1, elapsedMs / ProgressDurationMs);
|
||||||
|
|
||||||
|
if (_currentItem.Progress >= 1)
|
||||||
{
|
{
|
||||||
|
_currentItem.Progress = 1;
|
||||||
ProgressCompleted?.Invoke(_currentItem);
|
ProgressCompleted?.Invoke(_currentItem);
|
||||||
// 停止动画
|
// 停止动画
|
||||||
StopProgress();
|
StopProgress(resetProgress: false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CompositionTarget.Rendering += _renderHandler;
|
CompositionTarget.Rendering += _renderHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopProgress()
|
private void StopProgress(bool resetProgress = true)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (_renderHandler != null)
|
if (_renderHandler != null)
|
||||||
@ -138,7 +144,9 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
|
|||||||
|
|
||||||
if (_currentItem != null)
|
if (_currentItem != null)
|
||||||
{
|
{
|
||||||
|
if (resetProgress)
|
||||||
_currentItem.Progress = 0;
|
_currentItem.Progress = 0;
|
||||||
|
|
||||||
_currentItem = null;
|
_currentItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user