Because XAML code in a WPF application is handled most of the time by a run-time load. such as DynamicResource, but the XAML code parser usually throws an exception called Xamlparseexception in the process of compiling or running. However, the xamlparseexception exception provided is very simple or inaccurate. At this point we are going to get more exception information by using the workaround method:
We know that XAML code in a WPF application is parsed in the InitializeComponent method. This method is usually in the constructor of the Window object. So, we use. NET's exception mechanism to invoke method InitializeComponent:
The following are the referenced contents: 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//exception handling (innerexceptions) 12} 13} 14} |
So invoking InitializeComponent can help us get more accurate exception information when debugging.
In addition to the above exception capture mechanism, another scenario is to take advantage of the Visual Studio Exception dialog box. Exception under menu debugging (Debug) (Exception ...). dialog box, add System.Markup.XamlParseException to the Exception capture list by adding a button to the lower right. and select the Thrown check box. So you can get more information about xamlparseexception.