页面跳转
This commit is contained in:
parent
9c63156551
commit
5992e91e92
@ -1,8 +1,8 @@
|
|||||||
<Application x:Class="Wpf_AiSportsMicrospace.App"
|
<Application x:Class="Wpf_AiSportsMicrospace.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace"
|
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.Views"
|
||||||
StartupUri="Home.xaml">
|
StartupUri="Views/Main.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
46
Wpf_AiSportsMicrospace/Common/Utils.cs
Normal file
46
Wpf_AiSportsMicrospace/Common/Utils.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace Wpf_AiSportsMicrospace.Common
|
||||||
|
{
|
||||||
|
public static class Utils
|
||||||
|
{
|
||||||
|
private static MediaPlayer _bgPlayer;
|
||||||
|
public static void PlayBackgroundMusic(string musicFileName)
|
||||||
|
{
|
||||||
|
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
|
||||||
|
string musicPath = Path.Combine(projectRoot, "Resources", "Music", musicFileName);
|
||||||
|
|
||||||
|
if (_bgPlayer == null)
|
||||||
|
{
|
||||||
|
_bgPlayer = new MediaPlayer();
|
||||||
|
_bgPlayer.Volume = 0.5;
|
||||||
|
_bgPlayer.MediaEnded += (s, e) =>
|
||||||
|
{
|
||||||
|
_bgPlayer.Position = TimeSpan.Zero; // 循环播放
|
||||||
|
_bgPlayer.Play();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_bgPlayer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
_bgPlayer.Open(new Uri(musicPath, UriKind.Absolute));
|
||||||
|
_bgPlayer.Play();
|
||||||
|
}
|
||||||
|
public static void StopBackgroundMusic()
|
||||||
|
{
|
||||||
|
if (_bgPlayer != null)
|
||||||
|
{
|
||||||
|
_bgPlayer.Stop();
|
||||||
|
//_bgPlayer.Close(); // 如果想释放资源,可以取消注释
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using _3DTools;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
|||||||
BIN
Wpf_AiSportsMicrospace/Resources/Music/homeprojectselected.mp3
Normal file
BIN
Wpf_AiSportsMicrospace/Resources/Music/homeprojectselected.mp3
Normal file
Binary file not shown.
BIN
Wpf_AiSportsMicrospace/Resources/Music/musicjumprope.mp3
Normal file
BIN
Wpf_AiSportsMicrospace/Resources/Music/musicjumprope.mp3
Normal file
Binary file not shown.
@ -1,9 +1,8 @@
|
|||||||
<Window x:Class="Wpf_AiSportsMicrospace.Home"
|
<UserControl x:Class="Wpf_AiSportsMicrospace.Home"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl"
|
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl" Loaded="Window_Loaded">
|
||||||
Title="Home" Height="1080" Width="1920" Loaded="Window_Loaded">
|
<Grid VerticalAlignment="Bottom">
|
||||||
<Grid Height="1065" VerticalAlignment="Bottom">
|
|
||||||
<Grid.Background>
|
<Grid.Background>
|
||||||
<ImageBrush ImageSource="/Resources/Img/Album/home_bg.png" Stretch="UniformToFill"/>
|
<ImageBrush ImageSource="/Resources/Img/Album/home_bg.png" Stretch="UniformToFill"/>
|
||||||
</Grid.Background>
|
</Grid.Background>
|
||||||
@ -28,4 +27,4 @@
|
|||||||
Padding="0,100"
|
Padding="0,100"
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</UserControl>
|
||||||
@ -30,7 +30,7 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Home.xaml 的交互逻辑
|
/// Home.xaml 的交互逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Home : Window
|
public partial class Home : UserControl
|
||||||
{
|
{
|
||||||
private IHumanPredictor _humanPredictor;
|
private IHumanPredictor _humanPredictor;
|
||||||
private WebcamClient _webcamClient;
|
private WebcamClient _webcamClient;
|
||||||
@ -77,9 +77,11 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
_webcamClient.StartExtract();
|
_webcamClient.StartExtract();
|
||||||
|
|
||||||
StartFrameProcessing();
|
StartFrameProcessing();
|
||||||
|
|
||||||
|
Utils.PlayBackgroundMusic("homeprojectselected.mp3");
|
||||||
|
|
||||||
//coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
|
//coverFlow.ProgressCompleted += CoverFlow_ProgressCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CoverFlow_ProgressCompleted(CoverFlowItem item)
|
private void CoverFlow_ProgressCompleted(CoverFlowItem item)
|
||||||
{
|
{
|
||||||
// 停止抽帧线程/释放资源
|
// 停止抽帧线程/释放资源
|
||||||
@ -100,7 +102,6 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
|
|
||||||
// 根据图片跳转新窗口
|
// 根据图片跳转新窗口
|
||||||
string uri = item.ImageUri.ToString();
|
string uri = item.ImageUri.ToString();
|
||||||
Window newWindow = null;
|
|
||||||
|
|
||||||
//if (uri.EndsWith("1.jpg"))
|
//if (uri.EndsWith("1.jpg"))
|
||||||
// newWindow = new GroupJumpRope();
|
// newWindow = new GroupJumpRope();
|
||||||
@ -108,16 +109,13 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
// newWindow = new GroupJumpRope();
|
// newWindow = new GroupJumpRope();
|
||||||
//else if (uri.EndsWith("3.jpg"))
|
//else if (uri.EndsWith("3.jpg"))
|
||||||
// newWindow = new GroupJumpRope();
|
// newWindow = new GroupJumpRope();
|
||||||
|
// 找到主窗口,切换内容到 GroupJumpRopePage
|
||||||
|
|
||||||
newWindow = new GroupJumpRope();
|
var mainWin = Application.Current.MainWindow as Main;
|
||||||
|
if (mainWin != null)
|
||||||
if (newWindow != null)
|
|
||||||
{
|
{
|
||||||
Dispatcher.BeginInvoke(() =>
|
Utils.PlayBackgroundMusic("musicjumprope.mp3");
|
||||||
{
|
mainWin.SwitchPage(new GroupJumpRope(), true);
|
||||||
newWindow.Show(); // 先显示新窗口
|
|
||||||
this.Close(); // 再关闭当前窗口
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,5 +207,9 @@ namespace Wpf_AiSportsMicrospace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,12 +1,22 @@
|
|||||||
<Window x:Class="Wpf_AiSportsMicrospace.Views.GroupJumpRope"
|
<UserControl x:Class="Wpf_AiSportsMicrospace.Views.GroupJumpRope"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.Views"
|
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.Views"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d">
|
||||||
Title="多人跳绳" Height="450" Width="800">
|
<Grid VerticalAlignment="Center">
|
||||||
<Grid>
|
<Grid.Background>
|
||||||
|
<ImageBrush ImageSource="/Resources/Img/Album/home_bg.png" Stretch="UniformToFill"/>
|
||||||
|
</Grid.Background>
|
||||||
|
|
||||||
|
<!-- 顶部图片 -->
|
||||||
|
<Image
|
||||||
|
Source="/Resources/Img/Album/title.png"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
Width="615"
|
||||||
|
Margin="0,100,0,0"
|
||||||
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</UserControl>
|
||||||
|
|||||||
@ -11,13 +11,14 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using Wpf_AiSportsMicrospace.Common;
|
||||||
|
|
||||||
namespace Wpf_AiSportsMicrospace.Views
|
namespace Wpf_AiSportsMicrospace.Views
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GroupJumpRope.xaml 的交互逻辑
|
/// GroupJumpRope.xaml 的交互逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class GroupJumpRope : Window
|
public partial class GroupJumpRope : UserControl
|
||||||
{
|
{
|
||||||
public GroupJumpRope()
|
public GroupJumpRope()
|
||||||
{
|
{
|
||||||
|
|||||||
12
Wpf_AiSportsMicrospace/Views/Main.xaml
Normal file
12
Wpf_AiSportsMicrospace/Views/Main.xaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Window x:Class="Wpf_AiSportsMicrospace.Views.Main"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.Views"
|
||||||
|
mc:Ignorable="d" WindowState="Maximized">
|
||||||
|
<Grid>
|
||||||
|
<!-- 过渡容器 -->
|
||||||
|
<ContentControl x:Name="MainContent"/>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
98
Wpf_AiSportsMicrospace/Views/Main.xaml.cs
Normal file
98
Wpf_AiSportsMicrospace/Views/Main.xaml.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media.Media3D;
|
||||||
|
|
||||||
|
namespace Wpf_AiSportsMicrospace.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Main.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class Main : Window
|
||||||
|
{
|
||||||
|
public Main()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
// 默认显示首页
|
||||||
|
MainContent.Content = new Home();
|
||||||
|
}
|
||||||
|
public void SwitchPage(UserControl newPage, bool fromRight)
|
||||||
|
{
|
||||||
|
if (MainContent.Content == newPage) return;
|
||||||
|
|
||||||
|
var oldPage = MainContent.Content as UserControl;
|
||||||
|
|
||||||
|
if (oldPage != null)
|
||||||
|
{
|
||||||
|
// 旧页面动画
|
||||||
|
var oldTransformGroup = new TransformGroup();
|
||||||
|
var oldScale = new ScaleTransform(1, 1);
|
||||||
|
var oldSkew = new SkewTransform(0, 0);
|
||||||
|
var oldTranslate = new TranslateTransform(0, 0);
|
||||||
|
oldTransformGroup.Children.Add(oldScale);
|
||||||
|
oldTransformGroup.Children.Add(oldSkew);
|
||||||
|
oldTransformGroup.Children.Add(oldTranslate);
|
||||||
|
oldPage.RenderTransformOrigin = new Point(fromRight ? 1 : 0, 0.5); // 左右翻页中心
|
||||||
|
oldPage.RenderTransform = oldTransformGroup;
|
||||||
|
|
||||||
|
var scaleAnim = new DoubleAnimation(1, 0.7, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
var skewAnim = new DoubleAnimation(0, fromRight ? 45 : -45, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
var fadeAnim = new DoubleAnimation(1, 0.2, TimeSpan.FromMilliseconds(600));
|
||||||
|
var translateAnim = new DoubleAnimation(0, fromRight ? -ActualWidth : ActualWidth, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
|
||||||
|
oldScale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnim);
|
||||||
|
oldScale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnim);
|
||||||
|
oldSkew.BeginAnimation(SkewTransform.AngleYProperty, skewAnim);
|
||||||
|
oldTranslate.BeginAnimation(TranslateTransform.XProperty, translateAnim);
|
||||||
|
oldPage.BeginAnimation(OpacityProperty, fadeAnim);
|
||||||
|
|
||||||
|
fadeAnim.Completed += (s, e) =>
|
||||||
|
{
|
||||||
|
MainContent.Content = newPage;
|
||||||
|
AnimateNewPageEnhanced(newPage, fromRight);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MainContent.Content = newPage;
|
||||||
|
AnimateNewPageEnhanced(newPage, fromRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AnimateNewPageEnhanced(UserControl newPage, bool fromRight)
|
||||||
|
{
|
||||||
|
var transformGroup = new TransformGroup();
|
||||||
|
var scale = new ScaleTransform(0.7, 0.7);
|
||||||
|
var skew = new SkewTransform(fromRight ? -45 : 45, 0);
|
||||||
|
var translate = new TranslateTransform(fromRight ? ActualWidth : -ActualWidth, 0);
|
||||||
|
transformGroup.Children.Add(scale);
|
||||||
|
transformGroup.Children.Add(skew);
|
||||||
|
transformGroup.Children.Add(translate);
|
||||||
|
newPage.RenderTransformOrigin = new Point(fromRight ? 0 : 1, 0.5);
|
||||||
|
newPage.RenderTransform = transformGroup;
|
||||||
|
|
||||||
|
// 动画
|
||||||
|
var scaleAnim = new DoubleAnimation(0.7, 1, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
var skewAnim = new DoubleAnimation(fromRight ? -45 : 45, 0, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
var fadeAnim = new DoubleAnimation(0.2, 1, TimeSpan.FromMilliseconds(600));
|
||||||
|
var translateAnim = new DoubleAnimation(fromRight ? ActualWidth : -ActualWidth, 0, TimeSpan.FromMilliseconds(600)) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } };
|
||||||
|
|
||||||
|
scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnim);
|
||||||
|
scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnim);
|
||||||
|
skew.BeginAnimation(SkewTransform.AngleYProperty, skewAnim);
|
||||||
|
translate.BeginAnimation(TranslateTransform.XProperty, translateAnim);
|
||||||
|
newPage.BeginAnimation(OpacityProperty, fadeAnim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -32,10 +32,11 @@
|
|||||||
<None Remove="Resources\Img\Badge\4.png" />
|
<None Remove="Resources\Img\Badge\4.png" />
|
||||||
<None Remove="Resources\Img\Badge\5.jpg" />
|
<None Remove="Resources\Img\Badge\5.jpg" />
|
||||||
<None Remove="Resources\Img\Badge\logo.png" />
|
<None Remove="Resources\Img\Badge\logo.png" />
|
||||||
|
<None Remove="Resources\Music\homeprojectselected.mp3" />
|
||||||
|
<None Remove="Resources\Music\musicjumprope.mp3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="3DTools" Version="1.0.0" />
|
|
||||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||||
<PackageReference Include="Emgu.CV" Version="4.12.0.5764" />
|
<PackageReference Include="Emgu.CV" Version="4.12.0.5764" />
|
||||||
<PackageReference Include="Emgu.CV.runtime.windows" Version="4.12.0.5764" />
|
<PackageReference Include="Emgu.CV.runtime.windows" Version="4.12.0.5764" />
|
||||||
@ -142,6 +143,12 @@
|
|||||||
<Resource Include="Resources\Img\Badge\5.jpg">
|
<Resource Include="Resources\Img\Badge\5.jpg">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Resource>
|
</Resource>
|
||||||
|
<Resource Include="Resources\Music\homeprojectselected.mp3">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Resource>
|
||||||
|
<Resource Include="Resources\Music\musicjumprope.mp3">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Resource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user