This commit is contained in:
@@ -261,9 +261,17 @@
|
||||
<TextBlock Text="湿膜流量 (Wet Flow)" FontSize="11" Margin="0,0,15,0"/>
|
||||
<Rectangle Width="20" Height="2" Fill="Red" Margin="0,0,5,0"/>
|
||||
<TextBlock Text="干膜流量 (Dry Flow)" FontSize="11"/>
|
||||
<!-- 新增:干膜半流量标注(绿色虚线) -->
|
||||
<Rectangle Width="20" Height="2" Fill="Green" Margin="10,0,5,0"/>
|
||||
<TextBlock Text="干膜半流量 (Half of Dry Flow)" FontSize="11"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<oxy:PlotView Model="{Binding PlotModel}" Height="300" Margin="5"/>
|
||||
<!--<oxy:PlotView Model="{Binding PlotModel}" Height="300" Margin="5"/>-->
|
||||
|
||||
<oxy:PlotView x:Name="PlotViewStation1" Height="300" Margin="5" Visibility="Collapsed"/>
|
||||
<oxy:PlotView x:Name="PlotViewStation2" Height="300" Margin="5" Visibility="Collapsed"/>
|
||||
<oxy:PlotView x:Name="PlotViewStation3" Height="300" Margin="5" Visibility="Collapsed"/>
|
||||
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
@@ -6,51 +6,92 @@ namespace MembranePoreTester.Views
|
||||
{
|
||||
public partial class PoreDistributionView : UserControl
|
||||
{
|
||||
private MainViewModel _mainVM;
|
||||
|
||||
public PoreDistributionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
//DataContext = new ViewModels.PoreDistributionViewModel();
|
||||
|
||||
// 监听 IsVisible 变化
|
||||
this.IsVisibleChanged += (s, e) =>
|
||||
{
|
||||
if (this.DataContext is ViewModels.PoreDistributionViewModel vm)
|
||||
|
||||
if (this.DataContext is PoreDistributionViewModel vm)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"工位{vm.StationId} IsVisible={this.IsVisible}");
|
||||
vm.IsActive = this.IsVisible;
|
||||
if (!this.IsVisible)
|
||||
{
|
||||
// 离开孔分布界面时,停止自动采集
|
||||
//vm.StopCollecting();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.Loaded += OnLoaded;
|
||||
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 保留原有滚动功能
|
||||
var vm = this.DataContext as PoreDistributionViewModel;
|
||||
if (vm != null)
|
||||
{
|
||||
vm.Record.DataPoints.CollectionChanged += DataPoints_CollectionChanged;
|
||||
}
|
||||
|
||||
// 获取主窗口 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();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||
private void UpdateVisibility()
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e) { }
|
||||
|
||||
private void DataPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
|
||||
{
|
||||
// 滚动湿膜表格到底部
|
||||
ScrollDataGridToEnd(dgWetData);
|
||||
// 滚动干膜表格到底部
|
||||
ScrollDataGridToEnd(dgDryData);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user