From 56b28b9c9cfd17fc23515d493650b953ff9d14b5 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Mon, 16 Mar 2026 17:26:24 +0800 Subject: [PATCH] =?UTF-8?q?#0032=20=E4=BF=AE=E5=A4=8D=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=AE=B1DataContext=E4=BC=A0=E9=80=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImageProcessing/OperatorToolboxView.xaml | 2 ++ .../OperatorToolboxView.xaml.cs | 7 ++----- .../ImageProcessing/PipelineEditorView.xaml | 2 ++ .../PipelineEditorView.xaml.cs | 19 ++----------------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml index 1143c01..11bfd62 100644 --- a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml +++ b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml @@ -3,7 +3,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:prism="http://prismlibrary.com/" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" + prism:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="200"> diff --git a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml.cs b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml.cs index de1bfc0..5f2a575 100644 --- a/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml.cs +++ b/XplorePlane/Views/ImageProcessing/OperatorToolboxView.xaml.cs @@ -1,7 +1,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using Prism.Ioc; using Serilog; using XplorePlane.ViewModels; @@ -22,12 +21,10 @@ namespace XplorePlane.Views private void OnLoaded(object sender, RoutedEventArgs e) { - if (DataContext is not OperatorToolboxViewModel) - DataContext = ContainerLocator.Container.Resolve(); - ToolboxListBox.PreviewMouseLeftButtonDown += OnPreviewMouseDown; ToolboxListBox.PreviewMouseMove += OnPreviewMouseMove; - Log.Debug("OperatorToolboxView 原生拖拽源已注册"); + Log.Debug("OperatorToolboxView 原生拖拽源已注册, DataContext={Type}", + DataContext?.GetType().Name); } private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml index d78746b..270e9cc 100644 --- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml +++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml @@ -4,7 +4,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:prism="http://prismlibrary.com/" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" + prism:ViewModelLocator.AutoWireViewModel="True" d:DesignHeight="700" d:DesignWidth="350" mc:Ignorable="d"> diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs index ae58a7c..b9dfae5 100644 --- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs +++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs @@ -1,7 +1,5 @@ -using System; using System.Windows; using System.Windows.Controls; -using Prism.Ioc; using Serilog; using XplorePlane.ViewModels; @@ -17,21 +15,8 @@ namespace XplorePlane.Views private void OnLoaded(object sender, RoutedEventArgs e) { - try - { - if (DataContext is not PipelineEditorViewModel) - { - Log.Information("PipelineEditorView DataContext 不是 PipelineEditorViewModel(当前={Type}),正在从容器解析...", - DataContext?.GetType().Name); - DataContext = ContainerLocator.Container.Resolve(); - } - Log.Information("PipelineEditorView DataContext 类型={Type}, HashCode={Hash}", - DataContext?.GetType().Name, DataContext?.GetHashCode()); - } - catch (Exception ex) - { - Log.Error(ex, "PipelineEditorView 解析 DataContext 失败"); - } + Log.Information("PipelineEditorView DataContext 类型={Type}", + DataContext?.GetType().Name); PipelineListBox.AllowDrop = true; PipelineListBox.Drop += OnOperatorDropped;