using Prism.Ioc; using System; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using XP.Common.Logging.Interfaces; using XplorePlane.Services; using XplorePlane.ViewModels.Cnc; namespace XplorePlane.Views.Cnc { /// /// CNC editor main page view. /// public partial class CncPageView : UserControl { private CncInspectionModulePipelineViewModel _inspectionModulePipelineViewModel; public CncPageView() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs e) { CncEditorViewModel editorViewModel = DataContext as CncEditorViewModel; if (editorViewModel == null) { try { editorViewModel = ContainerLocator.Current?.Resolve(); DataContext = editorViewModel; } catch (Exception) { // keep existing DataContext if resolution fails } } if (editorViewModel == null || _inspectionModulePipelineViewModel != null) return; try { var imageProcessingService = ContainerLocator.Current.Resolve(); var persistenceService = ContainerLocator.Current.Resolve(); var logger = ContainerLocator.Current.Resolve(); _inspectionModulePipelineViewModel = new CncInspectionModulePipelineViewModel( editorViewModel, imageProcessingService, persistenceService, logger); InspectionModulePipelineEditor.DataContext = _inspectionModulePipelineViewModel; InspectionModulePipelineEmptyState.DataContext = _inspectionModulePipelineViewModel; } catch (Exception) { // keep page usable even if pipeline editor host setup fails } } private void CncTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { if (DataContext is CncEditorViewModel viewModel) { viewModel.SelectedNode = e.NewValue as CncNodeViewModel; } } } public class NullToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var invert = string.Equals(parameter as string, "Invert", StringComparison.OrdinalIgnoreCase); var isVisible = value != null; if (invert) { isVisible = !isVisible; } return isVisible ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }