在xaml中尝试/捕获?? [英] Try/Catch in the xaml??

查看:72
本文介绍了在xaml中尝试/捕获??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序包含对XML文件的绑定.应用启动的第一时间,该文件可能不存在.

在我的代码隐藏中,我正在使用适当的try/catch块测试该文件的存在,但该应用会生成异常:

System.Windows.Markup.XamlParseException未处理
Message ="无法创建在程序集'MyApp,Version = 1.0.0.7,Culture = neutral,PublicKeyToken中定义的'Window1'实例= null".调用的目标已引发异常.标记文件'Main.xaml'第1行的位置9错误.

LineLinesition = 9

在它甚至开始执行C#代码之前.

那么我该如何优雅地处理这种情况?

My app includes a binding to an XML file.   The firs time the app is started, this file may not exist.

In my codebehind I'm testing for the existence of this file with appropriate try/catch blocks but the app generates an exception:

System.Windows.Markup.XamlParseException was unhandled
  Message="Cannot create instance of 'Window1' defined in assembly 'MyApp, Version=1.0.0.7, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'Main.xaml' Line 1 Position 9."
  Source="PresentationFramework"
  LineNumber=1
  LinePosition=9

before it even begins executing the c# code.

So how can I handle this situation gracefully? 

推荐答案

->那么我该如何优雅地处理这种情况呢?

当您遇到这种类型的异常时,最好找出此异常的原因,并在继续进行操作之前对其进行修复,请您在此处发布您的XAML文件,以帮助我们了解哪种类型的XAML解析问题在这里吗?

谢谢
-> So how can I handle this situation gracefully?

When you encounter this type of exception, you'd better find out the cause of this exception, and fix it before moving on, could you please post your XAML file here to help us understand what type of XAML parsing issue you have here?

Thanks


这篇关于在xaml中尝试/捕获??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆