Exception:ControlTemplate 的 TargetType 必须是 Control、Page、PageFunctionBase 或相同的子类。“StackPanel”类型无效。

报错信息 1
ArgumentException: ControlTemplate 的 TargetType 必须是 Control、Page、PageFunctionBase 或相同的子类。“StackPanel”类型无效。
--Message: ControlTemplate 的 TargetType 必须是 Control、Page、PageFunctionBase 或相同的子类。“StackPanel”类型无效。
StackTrace:
   在 System.Windows.Controls.ControlTemplate.ValidateTargetType(Type targetType, String argName)
   在 System.Windows.Controls.ControlTemplate..ctor(Type targetType)
   在 DynamicClass.MainViewModel.添加右键菜单到画布()
   在 DynamicClass.MainViewModel.InitializeComponent()
   在 DynamicClass.MainViewModel..ctor()
   在 DynamicClass.a.<OnWindowCreated>d__e.MoveNext()
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

版本:1.44.23 2025-12-12 23:35 Microsoft Windows NT 10.0.22621.0