From 41955de0d3cc969ee7f9763485af520e49084e69 Mon Sep 17 00:00:00 2001
From: tanglong <842690096@qq.com>
Date: Sat, 18 Oct 2025 14:39:54 +0800
Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../MyUserControl/WxProgressBar.xaml | 22 ++++++--
.../MyUserControl/WxProgressBar.xaml.cs | 48 +++++++++++++-----
.../Resources/Img/Album/vs.png | Bin 0 -> 2989 bytes
.../Views/JumpRope/MusicJumpRope.xaml | 5 +-
.../Views/JumpRope/MusicJumpRope.xaml.cs | 37 +++++---------
.../Wpf_AiSportsMicrospace.csproj | 4 ++
6 files changed, 71 insertions(+), 45 deletions(-)
create mode 100644 Wpf_AiSportsMicrospace/Resources/Img/Album/vs.png
diff --git a/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml b/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml
index b5c3615..bae8d89 100644
--- a/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml
+++ b/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml
@@ -5,9 +5,21 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Name="root"
Height="30" Width="600">
-
-
-
-
-
+
diff --git a/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml.cs b/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml.cs
index 59c1c79..81435d3 100644
--- a/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml.cs
+++ b/Wpf_AiSportsMicrospace/MyUserControl/WxProgressBar.xaml.cs
@@ -21,6 +21,12 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
public WxProgressBar()
{
InitializeComponent();
+ this.SizeChanged += WxProgressBar_SizeChanged;
+ }
+
+ private void WxProgressBar_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ UpdateVisual();
}
#region 左右进度属性
@@ -31,7 +37,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
set
{
_leftProgress = Clamp(value, 0, 1);
- RightProgress = 1 - _leftProgress; // 左多右少
+ _rightProgress = 1 - _leftProgress;
UpdateVisual();
}
}
@@ -43,7 +49,7 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
set
{
_rightProgress = Clamp(value, 0, 1);
- _leftProgress = 1 - _rightProgress; // 右多左少
+ _leftProgress = 1 - _rightProgress;
UpdateVisual();
}
}
@@ -51,21 +57,39 @@ namespace Wpf_AiSportsMicrospace.MyUserControl
private void UpdateVisual()
{
- double width = ActualWidth;
- if (width <= 0) return;
+ double totalWidth = ActualWidth;
+ double totalHeight = ActualHeight;
+ if (totalWidth <= 0 || totalHeight <= 0) return;
- LeftBar.Width = width * _leftProgress;
- RightBar.Width = width * _rightProgress;
+ double barHeight = 30; // 进度条高度
+ double middleLineHeight = MiddleLine.Height;
+ // 左侧红条
+ LeftBar.Width = totalWidth * _leftProgress;
+ LeftBar.Height = barHeight;
+ Canvas.SetLeft(LeftBar, 0);
+ Canvas.SetTop(LeftBar, (totalHeight - barHeight) / 2);
+
+ // 右侧绿条
+ RightBar.Width = totalWidth * _rightProgress;
+ RightBar.Height = barHeight;
+ Canvas.SetLeft(RightBar, totalWidth - RightBar.Width);
+ Canvas.SetTop(RightBar, (totalHeight - barHeight) / 2);
+
+ // 分割线居中在红绿交界点
+ double middleX = LeftBar.Width - MiddleLine.Width / 2;
+ if (middleX < 0) middleX = 0;
+ if (middleX > totalWidth - MiddleLine.Width) middleX = totalWidth - MiddleLine.Width;
+
+ Canvas.SetLeft(MiddleLine, middleX);
+ Canvas.SetTop(MiddleLine, (totalHeight - middleLineHeight) / 2);
+
+ // 百分比文本居中显示
ProgressTextBlock.Text = $"{Math.Round(_leftProgress * 100)}% : {Math.Round(_rightProgress * 100)}%";
+ Canvas.SetLeft(ProgressTextBlock, (totalWidth - ProgressTextBlock.ActualWidth) / 2);
+ Canvas.SetTop(ProgressTextBlock, (totalHeight - ProgressTextBlock.ActualHeight) / 2);
}
private double Clamp(double value, double min, double max) => value < min ? min : value > max ? max : value;
-
- protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
- {
- base.OnRenderSizeChanged(sizeInfo);
- UpdateVisual();
- }
}
}
diff --git a/Wpf_AiSportsMicrospace/Resources/Img/Album/vs.png b/Wpf_AiSportsMicrospace/Resources/Img/Album/vs.png
new file mode 100644
index 0000000000000000000000000000000000000000..924e879e440d16e7536d5b28a7d38a1c0812e323
GIT binary patch
literal 2989
zcmXw52{=?=A0`swYeAHqDMJXUY<)4-k-eGhTh{DZBFm7-UYHqVi=ix)T?i>VGh>TN
zGGkX{``ee9`<Ma>2k7PU}s=p;6&MsNCt*u&L##ZZ4iVYXv)GGPaSA1E6Y!gLJJCMV*IG))^s|Z
zVr&UoFoma((E@_scK+nOE1E^4speKw=2p+DGf)D8sT2JWLx05D|WKIt{?U3yw+#vpDJijxqo^5fQ#90fEAqFH<{fT}T5kg~0d$%(S%~00S8`
z8VzIz;{g*hkR1&EP4xd3LSTF+%q;==>cN(uq~w%^6+j>&eL&>!=ukb(8#_tXi4IuW
z+r&}+rUv&U+6ssV3jqcM5ts+qzxpBdNWX)H#eXrt?DC6jlzFl;0cv@m|pzLUMOpTB6Ve$iBwKQmmhFb-%#TdMCSMOr3C?kz4>k-As<
zY}>#&BL$in-T8akjSE&QJ(kH8wPx#+lGyBh0FMH^-i
zugvJt5|pzot2Zq^v(nvw-mrL!wh`ocGnw&HQ39hSHXDBa{`=(M0aabH5%kI=2Kp%J
zpwQ;@OSs$*-wK6@^{YguIZQyKj}-UI6Ak(FKYw}wm2M3pAi7J0;)FW{8AAn-Y;FxT
zGuR56mTuJZRkryIuTK05`N{`EVtspYbF0A5^^5`~`s6^3BG3-XI(P()Ye0`jLiAle
z95OJl3L~{NP$9XK*}IxtNba6m*BhR&EV$M^R*^hER`zHSL#=E$+*bWKcjwc@(QMCZ&%7WF>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QcoTVl!L@r
z15aswje7wvV^`@&Guw~C*KiiZ8!_N`N#UEHPfr#1+r=DiZ{B=Xg{L)k1)aeDI%1ys
z;v#pFKzMK$d#1TRxXk7G>zQ*cEdE@!M&iFdrtIws7_$2s&tj(ATg*;61?7@TT9s2o
zunX9Y4m$0_+1(t`z@{AZ?d$TV^h)jKm_yYSQiZ9=;!JUKzqU(-#I*Y|o%0gRLE;h&
zyOkCaX{K$Rsh{GR>@AzH98(d|DoXNI=##PO9z=V6?ugnPj{97q<2y<_HY12a!v0e<
z;dOi2qgNcq%b&5nD;{n0nz#G8!FlT+dMnH<>BxUHgp=C}Y27@|m%sd^vC{-*D=}_bQ}MB7
z`a`K8Y$0?t+8uS(vCH#Ek^f@f%4ksLx2`+ku|c-m7?jXl$j&KSw;4AlUtUR{KkNH;
z770S>PnW7qV_kiNzDJ_8I?F9PCds}pz*@BY7A@bf-?Wl6E)!jR*1yKhZ0kRp*33w{Xi?=c
zRH)9prD=DILWj!VkFL|ZP_Ny7x3QDz!Li4Q_)
-
-
+
-
+
diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs
index 6ad2b1f..9c7911a 100644
--- a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs
+++ b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs
@@ -59,34 +59,21 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
private async void UserControl_Loaded(object sender, RoutedEventArgs e)
{
- //Random _rand = new Random();
- //// 初始化进度
- //PkBar.LeftProgress = 0.5; // 左右各占50%
- //await Task.Delay(500);
-
- //for (int i = 0; i < 500; i++)
- //{
- // await Task.Delay(300);
-
- // // 随机生成一个变化值 0~0.1
- // double delta = _rand.NextDouble() * 0.1;
-
- // // 随机决定左增加还是右增加
- // if (_rand.Next(0, 2) == 0)
- // {
- // // 左增加 → 右减少
- // PkBar.LeftProgress = Math.Min(1, PkBar.LeftProgress + delta);
- // }
- // else
- // {
- // // 右增加 → 左减少
- // PkBar.RightProgress = Math.Min(1, PkBar.RightProgress + delta);
- // }
- //}
-
DrawCirclesWithText();
// 播放音乐
PlayMusic("raisehand.mp3");
+
+ Random rnd = new Random();
+
+ // 模拟 20 次随机更新
+ for (int i = 0; i < 200; i++)
+ {
+ // 随机左右进度变化,保证总和=1
+ double left = rnd.NextDouble(); // 0~1
+ PkBar.LeftProgress = left; // RightProgress 自动 1-left
+
+ await Task.Delay(1000); // 200ms 间隔,不卡UI线程
+ }
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
diff --git a/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj b/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj
index 50a781f..51d4079 100644
--- a/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj
+++ b/Wpf_AiSportsMicrospace/Wpf_AiSportsMicrospace.csproj
@@ -28,6 +28,7 @@
+
@@ -182,6 +183,9 @@
Always
+
+ Always
+
Always