2026-03-27 21:35:32 +08:00
|
|
|
|
using MembranePoreTester.ViewModels;
|
2026-04-02 18:06:10 +08:00
|
|
|
|
using System.Windows;
|
2026-03-27 21:35:32 +08:00
|
|
|
|
using System.Windows.Controls;
|
2026-02-27 16:03:49 +08:00
|
|
|
|
|
|
|
|
|
|
namespace MembranePoreTester.Views
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class PoreDistributionView : UserControl
|
|
|
|
|
|
{
|
2026-04-10 18:01:18 +08:00
|
|
|
|
private MainViewModel _mainVM;
|
|
|
|
|
|
|
2026-02-27 16:03:49 +08:00
|
|
|
|
public PoreDistributionView()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2026-03-27 21:35:32 +08:00
|
|
|
|
|
|
|
|
|
|
this.IsVisibleChanged += (s, e) =>
|
|
|
|
|
|
{
|
2026-04-10 18:01:18 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.DataContext is PoreDistributionViewModel vm)
|
2026-03-27 21:35:32 +08:00
|
|
|
|
{
|
2026-04-10 18:01:18 +08:00
|
|
|
|
System.Diagnostics.Debug.WriteLine($"工位{vm.StationId} IsVisible={this.IsVisible}");
|
2026-03-27 21:35:32 +08:00
|
|
|
|
vm.IsActive = this.IsVisible;
|
2026-04-12 16:46:55 +08:00
|
|
|
|
if (this.IsVisible)
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.RefreshPlot(); // 新增这一行
|
|
|
|
|
|
}
|
2026-03-27 21:35:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-04-02 18:06:10 +08:00
|
|
|
|
|
|
|
|
|
|
this.Loaded += OnLoaded;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2026-04-10 18:01:18 +08:00
|
|
|
|
// 保留原有滚动功能
|
2026-04-02 18:06:10 +08:00
|
|
|
|
var vm = this.DataContext as PoreDistributionViewModel;
|
|
|
|
|
|
if (vm != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
vm.Record.DataPoints.CollectionChanged += DataPoints_CollectionChanged;
|
|
|
|
|
|
}
|
2026-04-10 18:01:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取主窗口 ViewModel
|
|
|
|
|
|
_mainVM = Application.Current.MainWindow?.DataContext as MainViewModel;
|
|
|
|
|
|
if (_mainVM == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 为每个工位订阅 PropertyChanged,实时更新对应的 PlotView 模型
|
|
|
|
|
|
for (int i = 0; i < _mainVM.Stations.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int stationId = i + 1;
|
|
|
|
|
|
var stationVm = _mainVM.Stations[i].PoreDistributionVM;
|
|
|
|
|
|
stationVm.PropertyChanged += (s, ev) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ev.PropertyName == nameof(PoreDistributionViewModel.PlotModel))
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (stationId)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 1: PlotViewStation1.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
case 2: PlotViewStation2.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
case 3: PlotViewStation3.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
// 初始化当前模型
|
|
|
|
|
|
if (stationVm.PlotModel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (stationId)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 1: PlotViewStation1.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
case 2: PlotViewStation2.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
case 3: PlotViewStation3.Model = stationVm.PlotModel; break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听当前 DataContext 变化,切换可见性
|
|
|
|
|
|
this.DataContextChanged += (s, ev) => UpdateVisibility();
|
|
|
|
|
|
UpdateVisibility();
|
2026-04-02 18:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-10 18:01:18 +08:00
|
|
|
|
private void UpdateVisibility()
|
2026-04-02 18:06:10 +08:00
|
|
|
|
{
|
2026-04-10 18:01:18 +08:00
|
|
|
|
if (this.DataContext is PoreDistributionViewModel vm)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlotViewStation1.Visibility = vm.StationId == 1 ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
PlotViewStation2.Visibility = vm.StationId == 2 ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
PlotViewStation3.Visibility = vm.StationId == 3 ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
}
|
2026-04-02 18:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-10 18:01:18 +08:00
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e) { }
|
|
|
|
|
|
|
2026-04-02 18:06:10 +08:00
|
|
|
|
private void DataPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
|
|
|
|
|
|
{
|
2026-04-12 20:22:21 +08:00
|
|
|
|
//ScrollDataGridToEnd(dgWetData);
|
|
|
|
|
|
//ScrollDataGridToEnd(dgDryData);
|
2026-04-02 18:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ScrollDataGridToEnd(DataGrid dataGrid)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dataGrid.Items.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
dataGrid.ScrollIntoView(dataGrid.Items[dataGrid.Items.Count - 1]);
|
|
|
|
|
|
}
|
2026-02-27 16:03:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|