【问题标题】:XAML design not loading in visual studioXAML 设计未在 Visual Studio 中加载
【发布时间】: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


【解决方案1】:

我能够解决这个问题。它与项目缓存有关。我按照以下步骤解决了它:

  1. 关闭 Visual Studio
  2. 删除 .vs、bin 和 obj 文件
  3. 启动VS并清理项目
  4. 重建项目

完成这些步骤后,我能够打开所有 .xaml 文件。

【讨论】:

    【解决方案2】:

    如果我不理解您的问题,我很抱歉。听起来您是在说设计器不工作,但运行它。

    如果是这种情况,Visual Studio 将无法运行以 x64 模式呈现 xaml(我相信称为 xdescproc)的应用程序。要解决此问题,请尝试切换到 x86。如果这可行,但您不想将 x86 作为选项,您可以尝试配置支持 x64 但仍允许 x86 的 AnyCPU 配置(这意味着在设计模式下它显示 x86,这将允许 xdescproc 运行) .

    【讨论】:

      【解决方案3】:

      就我而言,不知何故,我的项目的目标平台已更改为 x64。我将其恢复为旧配置,之后 XAML 设计器再次开始工作。

      【讨论】:

        猜你喜欢
        • 2014-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-06
        • 2016-03-09
        • 2016-01-15
        相关资源
        最近更新 更多