How to view the procedural code for any xaml file

对着背影说爱祢 提交于 2020-01-04 04:09:07

问题


I'm working in Visual Studio 2012 with xaml to create an application. When I make a new solution and WPF project and look at the xaml in the application file, I see xmlns, a startupuri, and a tag for application.resources.

When I want to see the code-behind that these tags are creating, I have only the .cs file with maybe a few things in it and the mysterious InitializeComponent() that performs all of the parsing. Here's an example of what it looks like:

public partial class MainWindow : Window //This is generated with a wpf project.
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

If possible, how can I view the procedurally generated code that InitializeComponent is creating?


回答1:


I don't think that the complete xaml source gets compiled into .g.cs files.

Quoting this codeproject article:

When you compile a WPF application in Visual Studio it will compile your XAML files into a compressed representation known as Binary Application Markup Language (BAML). The BAML is then saved as a resource in the resultant assembly. When that assembly is loaded and the resource is requested, the BAML is streamed out and very quickly turned into the object graph described by the original XAML.




回答2:


In the project directory, under the obj and Debug folders should be files labeled .g.cs that correspond to existing files. Presumably, these are Generated C-Sharp files that contain the generated code that I was looking for.



来源:https://stackoverflow.com/questions/25411608/how-to-view-the-procedural-code-for-any-xaml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!