Files
VacuumPressureMembranePoreS…/Views/MainWindow.xaml.cs

107 lines
4.0 KiB
C#
Raw Normal View History

2026-03-02 18:50:30 +08:00
using MembranePoreTester.ViewModels;
using System.Windows;
2026-03-27 21:35:32 +08:00
using System.Windows.Controls;
2026-03-24 19:33:35 +08:00
using System.Windows.Input;
2026-03-27 21:35:32 +08:00
using System.Windows.Media;
2026-02-27 16:03:49 +08:00
namespace MembranePoreTester.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
2026-03-02 18:50:30 +08:00
HistoryWindow.LoadRecordEvent += OnLoadRecord;
}
private void OnLoadRecord(object sender, LoadRecordEventArgs e)
{
var mainVM = DataContext as MainViewModel;
if (mainVM == null) return;
// 根据工位和类型找到对应的 ViewModel
if (e.Type == "泡点法")
{
var targetVM = mainVM.Stations[e.TargetStation - 1].BubblePointVM;
targetVM.LoadFromDatabase(e.RecordId);
}
else
{
var targetVM = mainVM.Stations[e.TargetStation - 1].PoreDistributionVM;
targetVM.LoadFromDatabase(e.RecordId);
}
}
private void OpenHistory_Click(object sender, RoutedEventArgs e)
{
var mainVM = DataContext as MainViewModel;
if (mainVM == null) return;
2026-03-19 20:40:54 +08:00
// 获取当前选中的工位索引(假设选项卡控件是 TabControl名称为 stationTabControl
// 需要在 XAML 中为 TabControl 设置 x:Name="stationTabControl"
int currentStation = stationTabControl.SelectedIndex + 1; // 假设索引从0开始
2026-03-02 18:50:30 +08:00
var historyWin = new HistoryWindow { SelectedStation = currentStation };
historyWin.ShowDialog();
2026-02-27 16:03:49 +08:00
}
2026-03-24 19:33:35 +08:00
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.P)
{
var win = new ParameterWindow();
win.Owner = this;
win.ShowDialog();
}
}
2026-03-27 21:35:32 +08:00
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedStation = stationTabControl.SelectedItem as MainViewModel.StationItem;
if (selectedStation != null)
{
var content = stationTabControl.SelectedContent as ContentPresenter;
if (content != null)
{
var innerTabControl = FindVisualChild<TabControl>(content);
if (innerTabControl != null)
{
var selectedTabItem = innerTabControl.SelectedItem as TabItem;
bool isPoreDistributionActive = selectedTabItem?.Header?.ToString() == "孔分布测试";
// 关键:设置 StationItem 的状态
selectedStation.IsPoreDistributionActive = isPoreDistributionActive;
selectedStation.PoreDistributionVM.IsActive = isPoreDistributionActive;
if (isPoreDistributionActive)
{
// 切换到孔分布时,清空之前的数据
selectedStation.PoreDistributionVM.ClearData();
}
else
{
// 离开孔分布界面时,停止自动采集
selectedStation.PoreDistributionVM.StopCollecting();
}
}
}
}
}
// 辅助方法:查找 Visual Tree 中的指定类型元素
private T FindVisualChild<T>(DependencyObject parent) where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is T t) return t;
var result = FindVisualChild<T>(child);
if (result != null) return result;
}
return null;
}
2026-02-27 16:03:49 +08:00
}
}