using System.Windows; using XP.ImageProcessing.RoiControl.Controls; namespace XplorePlane.Views.ImageProcessing { public partial class BgaMeasurePanel : Window { private PolygonRoiCanvas _canvas; public BgaMeasurePanel() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs e) { try { var mainWin = Owner as MainWindow; if (mainWin != null) _canvas = FindChild(mainWin); } catch { } // 模式切换:通知 canvas 切换气泡/焊球 RbVoid.Checked += (s, ev) => { if (_canvas != null) _canvas.SetBgaDrawBall(false); }; RbBall.Checked += (s, ev) => { if (_canvas != null) _canvas.SetBgaDrawBall(true); }; // VoidLimit 同步 SliderVoidLimit.ValueChanged += (s, ev) => { TbVoidLimit.Text = SliderVoidLimit.Value.ToString("F1"); _canvas?.SetBgaVoidLimit(SliderVoidLimit.Value); }; // 监听测量完成事件更新结果 if (_canvas != null) { _canvas.MeasureCompleted += (s, ev) => { if (ev is MeasureCompletedEventArgs args && args.MeasureType == "BgaVoid") { TbResult.Text = $"空隙率: {args.Distance:F1}%"; } }; } } private void Finish_Click(object sender, RoutedEventArgs e) { Close(); } private static T FindChild(DependencyObject parent) where T : DependencyObject { int count = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < count; i++) { var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i); if (child is T t) return t; var result = FindChild(child); if (result != null) return result; } return null; } } }