更新最新

This commit is contained in:
GukSang.Jin
2026-06-02 18:53:31 +08:00
parent 212dca6abe
commit 34f03d0ed0
4 changed files with 190 additions and 20 deletions

View File

@@ -334,16 +334,38 @@
<StackPanel Grid.Row="2" Spacing="8">
<TextBlock Text="垂直架" FontWeight="SemiBold"/>
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
<Button Content="提升" Classes="motion compact" Command="{Binding LiftCommand}"/>
<Button Grid.Column="1" Content="下降" Classes="motion compact" Command="{Binding LowerCommand}"/>
<Button Content="提升"
Classes="motion compact"
Tag="Lift"
PointerPressed="MotionButton_PointerPressed"
PointerReleased="MotionButton_PointerReleased"
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
<Button Grid.Column="1"
Content="下降"
Classes="motion compact"
Tag="Lower"
PointerPressed="MotionButton_PointerPressed"
PointerReleased="MotionButton_PointerReleased"
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
</Grid>
</StackPanel>
<StackPanel Grid.Row="3" Spacing="8">
<TextBlock Text="水平板" FontWeight="SemiBold"/>
<Grid ColumnDefinitions="*,*" ColumnSpacing="8">
<Button Content="左移" Classes="motion compact" Command="{Binding MoveLeftCommand}"/>
<Button Grid.Column="1" Content="右移" Classes="motion compact" Command="{Binding MoveRightCommand}"/>
<Button Content="左移"
Classes="motion compact"
Tag="MoveLeft"
PointerPressed="MotionButton_PointerPressed"
PointerReleased="MotionButton_PointerReleased"
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
<Button Grid.Column="1"
Content="右移"
Classes="motion compact"
Tag="MoveRight"
PointerPressed="MotionButton_PointerPressed"
PointerReleased="MotionButton_PointerReleased"
PointerCaptureLost="MotionButton_PointerCaptureLost"/>
</Grid>
</StackPanel>

View File

@@ -1,23 +1,111 @@
using Avalonia.Controls;
using Avalonia.Input;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
using SukiUI.Controls;
using System;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Views
{
public partial class MainWindow : SukiWindow
{
private readonly HashSet<string> activeMotionTags = [];
public MainWindow()
{
InitializeComponent();
Closed += OnClosed;
Deactivated += OnDeactivated;
}
private void OnClosed(object? sender, EventArgs e)
private async void MotionButton_PointerPressed(object? sender, PointerPressedEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
if (!activeMotionTags.Add(tag))
{
return;
}
e.Pointer.Capture(button);
e.Handled = true;
await StartMotionAsync(viewModel, tag);
}
private async void MotionButton_PointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
e.Pointer.Capture(null);
e.Handled = true;
await StopMotionAsync(viewModel, tag);
}
private async void MotionButton_PointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
if (sender is not Button button || button.Tag is not string tag || DataContext is not MainWindowViewModel viewModel)
{
return;
}
await StopMotionAsync(viewModel, tag);
}
private async void OnDeactivated(object? sender, EventArgs e)
{
await StopAllMotionAsync();
}
private async void OnClosed(object? sender, EventArgs e)
{
await StopAllMotionAsync();
if (DataContext is MainWindowViewModel viewModel)
{
viewModel.Dispose();
}
}
private static Task StartMotionAsync(MainWindowViewModel viewModel, string tag) =>
tag switch
{
"Lift" => viewModel.StartLiftMotionAsync(),
"Lower" => viewModel.StartLowerMotionAsync(),
"MoveLeft" => viewModel.StartMoveLeftMotionAsync(),
"MoveRight" => viewModel.StartMoveRightMotionAsync(),
_ => Task.CompletedTask
};
private async Task StopMotionAsync(MainWindowViewModel viewModel, string tag)
{
if (!activeMotionTags.Remove(tag))
{
return;
}
await (tag switch
{
"Lift" => viewModel.StopLiftMotionAsync(),
"Lower" => viewModel.StopLowerMotionAsync(),
"MoveLeft" => viewModel.StopMoveLeftMotionAsync(),
"MoveRight" => viewModel.StopMoveRightMotionAsync(),
_ => Task.CompletedTask
});
}
private async Task StopAllMotionAsync()
{
activeMotionTags.Clear();
if (DataContext is MainWindowViewModel viewModel)
{
await viewModel.StopAllMotionAsync();
}
}
}
}