#0032 修复工具箱DataContext传递问题

This commit is contained in:
zhengxuan.zhang
2026-03-16 17:26:24 +08:00
parent 3f89710850
commit 56b28b9c9c
4 changed files with 8 additions and 22 deletions
@@ -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">
@@ -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<OperatorToolboxViewModel>();
ToolboxListBox.PreviewMouseLeftButtonDown += OnPreviewMouseDown;
ToolboxListBox.PreviewMouseMove += OnPreviewMouseMove;
Log.Debug("OperatorToolboxView 原生拖拽源已注册");
Log.Debug("OperatorToolboxView 原生拖拽源已注册, DataContext={Type}",
DataContext?.GetType().Name);
}
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
@@ -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">
@@ -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<PipelineEditorViewModel>();
}
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;