惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
T
Threatpost
P
Privacy International News Feed
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
I
Intezer
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
博客园 - 聂微东
博客园 - 叶小钗
Cisco Talos Blog
Cisco Talos Blog
H
Help Net Security
S
Schneier on Security
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
T
Tor Project blog
月光博客
月光博客
NISL@THU
NISL@THU
A
About on SuperTechFans
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
G
Google Developers Blog
W
WeLiveSecurity
P
Palo Alto Networks Blog
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
博客园 - 司徒正美
L
LINUX DO - 热门话题
小众软件
小众软件

博客园 - 赖仪灵

分享几个简单的WPF控件(代码) 设置WPF窗口相对于非WPF窗口的位置 上海.NET俱乐部--微软社区巡展VSTS上海专题活动 WPF关于WindowInteropHelper的一个BUG WPF全景体验 最优化WPF 3D性能(基于“Tier-2”硬件) Windows Vista桌面窗口管理器(3) 闲话WPF之二六(WPF性能优化点) 闲话WPF之二五(WPF中的ControlTemplate [3]) 闲话WPF之二四(WPF中的ControlTemplate [2]) Windows Vista桌面窗口管理器(2) 闲话WPF之二三(WPF中的ControlTemplate [1]) 闲话WPF之二二(WPF中的Style) Windows Vista桌面窗口管理器(1) 闲话WPF之二一(WPF中的数据处理 [3]) 闲话WPF之二十(WPF中的传递事件 [2] ) 闲话WPF之十九(WPF中的传递事件 [1] ) 闲话WPF之十八(WPF中的资源 [4] ) 闲话WPF之十七(WPF中的资源 [3])
捕捉WPF应用程序中XAML代码解析异常
赖仪灵 · 2007-05-28 · via 博客园 - 赖仪灵

由于WPF应用程序中XAML代码在很多时候是运行时加载处理的。比如DynamicResource,但是在编译或者运行的过程中,编写的XAML代码很可能有错误,此时XAML代码解析器通常会抛出称为XamlParseException的异常。但是抛出的XamlParseException异常提供的信息非常简单,或者是很不准确。此时我们关于通过对变通的方法来获取更多的异常信息:

我们知道,WPF应用程序中的XAML代码是在InitializeComponent方法中解析的。而这个方法通常位于窗口对象的构造函数之中。因此,我们利用.NET的异常机制来调用方法InitializeComponent:

 1 public partial class Window1 : System.Windows.Window 
 2 
 3     public Window1() 
 4     { 
 5         try 
 6         { 
 7             InitializeComponent(); 
 8         } 
 9         catch ( Exception ex )
10         {
11             // 异常处理(InnerExceptions)
12         } 
13     } 
14 }

如此调用InitializeComponent能帮助我们在调试时获得更准确的异常信息。

除了上面的异常捕捉机制,另一种方案是利用Visual Studio的异常对话框。在菜单调试(Debug)下的异常(Exception...)对话框中,通过右下的添加按钮把System.Markup.XamlParseException加入到异常捕捉列表中。并选中Thrown复选框。如此也能获取更多的关于XamlParseException的信息。