1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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.Imaging;
- using System.Windows.Shapes;
- namespace MV485.Dlg
- {
- /// <summary>
- /// DlgSearchDevices.xaml 的交互逻辑
- /// </summary>
- public partial class DlgSearchDevices : Window
- {
- public event Action OnStopTask; // 用于通知任务被停止
- public DlgSearchDevices()
- {
- InitializeComponent();
- }
- public void UpdateProgress(int currentNum, int totalNum)
- {
- Dispatcher.BeginInvoke(new Action(() =>
- {
- double progress = (double)currentNum / totalNum * 100;
- progressBar.Value = progress;
- progressText.Text = $"正在搜素:{currentNum}/{totalNum}";
- }));
- }
- private void StopButton_Click(object sender, RoutedEventArgs e)
- {
- stopButton.IsEnabled = false; //防止连续点击
- // 触发停止任务事件
- OnStopTask?.Invoke();
- // 可选:更新状态,提示任务已停止
- progressText.Text = "任务已停止";
- }
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- // 恢复主界面操作
- Application.Current.MainWindow.IsEnabled = true;
- }
- //--------------------------------------------------------
- }
- }
|