An error occurred while capturing the XAML code parsing in the WPF application.

Source: Internet
Author: User

In WPF applications, XAML code is often loaded and processed during runtime. For example, DynamicResource. However, during compilation or running, the compiled XAML code may be incorrect. In this case, The XAML code parser usually throws an exception called XamlParseException. However, the information provided by the XamlParseException thrown is very simple or inaccurate. In this case, we can obtain more exception information through the work und:

As we know, The XAML code in the WPF application is parsed in the InitializeComponent method. This method is usually located in the constructor of the window object. Therefore, we use the. NET exception mechanism to call the InitializeComponent method:

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}

Calling InitializeComponent can help us obtain more accurate exception information during debugging.

In addition to the exception capture mechanism above, another solution is to use the exception dialog box of Visual Studio. In the Exception (Exception...) dialog box under menu debugging (Debug), add System. Markup. XamlParseException to the Exception capture list through the Add button in the lower right. Select the Thrown check box. In this way, you can obtain more information about XamlParseException.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.