【发布时间】:2019-07-25 07:52:05
【问题描述】:
我正在尝试在 Visual Studio 中加载 xaml 文件,但它引发了异常,但是当我运行应用程序时,设计和所有功能都非常好。例外情况如下:
InvalidCastException: Unable to cast object of type 'System.Windows.Application' to type 'Omnia.PIE.VTA.App'.
at Omnia.PIE.VTA.MainWindow.get_Instance()
at Omnia.PIE.VTA.Views.AccountHolderInfo.UserControl_Loaded(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
抱歉,我是 Visual Studio 的初学者,花了几个小时后我仍然无法解决它。
【问题讨论】:
-
请发布您的 *.xaml 文件的完整标记以及 *.xaml.cs 文件的代码
-
Form 包含一个控件
Omnia.PIE.VTA.Views.AccountHolderInfo,Visual Studio XAML 设计器尝试初始化该控件,但它在UserControl_Loaded中引发异常。如果你有AccountHolderInfo的源代码,你可以调试它。打开第二个 Visual Studio,转到 Debug 菜单,然后 Attach to Process,搜索 devenv.exe 并选择它。然后打开 Debug > Windows > Exception settings 并标记“Common Language Runtime Exceptions”。然后尝试再次打开 XAML 编辑器,Visual Studio 的第二个实例会中断并显示异常发生的位置。 -
请不要为与 IDE 本身无关的问题设置
visual-studio标签。如果您不确定某个特定标签是否适用,您应该阅读标签说明。我从你的问题中删除了这个标签。
标签: c# wpf xaml wpf-controls xaml-designer