51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System.Windows;
|
|
using Prism.Ioc;
|
|
using XP.ImageProcessing.RoiControl.Controls;
|
|
using XplorePlane.Services.MainViewport;
|
|
using XplorePlane.ViewModels.ImageProcessing;
|
|
|
|
namespace XplorePlane.Views.ImageProcessing
|
|
{
|
|
public partial class VoidDetectionPanel : Window
|
|
{
|
|
public VoidDetectionPanel()
|
|
{
|
|
InitializeComponent();
|
|
var viewportService = ContainerLocator.Current?.Resolve<IMainViewportService>();
|
|
DataContext = new VoidDetectionViewModel(viewportService);
|
|
|
|
Loaded += (s, e) =>
|
|
{
|
|
var mainWin = Owner as MainWindow;
|
|
if (mainWin != null)
|
|
{
|
|
var canvas = FindChild<PolygonRoiCanvas>(mainWin);
|
|
if (DataContext is VoidDetectionViewModel vm)
|
|
vm.SetCanvas(canvas);
|
|
}
|
|
};
|
|
|
|
Closed += (s, e) =>
|
|
{
|
|
if (DataContext is VoidDetectionViewModel vm)
|
|
vm.RestoreContextMenu();
|
|
};
|
|
}
|
|
|
|
private void Close_Click(object sender, RoutedEventArgs e) => Close();
|
|
|
|
private static T FindChild<T>(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<T>(child);
|
|
if (result != null) return result;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|