c# - XAML 设计未在 Visual Studio 中加载

标签 c# wpf xaml wpf-controls xaml-designer

我正在尝试在 visual studio 中加载 xaml 文件,但它引发了异常,但是当我运行应用程序时,设计和所有功能都非常好。异常(exception)情况如下:

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 的初学者,花了几个小时后我仍然无法解决它。

最佳答案

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

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

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

关于c# - XAML 设计未在 Visual Studio 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196907/

相关文章:

WPF 到 silverlight xaml 问题

c# - Xamarin XAML : Placing a Grid over an Image (responsive to screen size)

c# - 在 Windows 中的任意位置插入文本。 (如自动图文集/智能感知)

c# - .NET Core 2.0 可以使用 OData v2 吗?

c# - RSA客户端服务器加密解密

c# - 如何将一系列名称分成不同的行

wpf - 带有样式的自定义 WPF ListView(使用 DataTemplate) - 如何添加标题?

c# - WPF RichTextBox 作为用于记录目的的文本队列

c# - HTML:编码错误

c# - Xamarin.Forms 如何将多个页面的 BindingContext 设置为同一个 ViewModel?