Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>InitializeComponent</code> is a method defined on the interface <code>System.Windows.Markup.IComponentConnector</code> and is used for loading the compiled page of a component. </p> <p>See <code>MSDN</code> excerpt below from this <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.icomponentconnector.initializecomponent.aspx" rel="nofollow noreferrer">link</a> which has more info:</p> <p><code>IComponentConnector</code> is used internally by <code>Baml2006Reader</code>.</p> <p>Implementations of <code>InitializeComponent</code> are widely observable as part of the infrastructure provided by frameworks or technologies that use <code>XAML</code> combined with application and programming models. For example, whenever you look at the generated classes for XAML root elements in WPF pages and applications, you will see InitializeComponent defined in the output. That method also exists in the compiled assembly and plays a role in the WPF application model of loading the XAML UI content at XAML parse time (and I suppose hence <code>InitializeComponent</code> has to be in an interface and be public so that other outside WPF related assemblies can make use of it).</p> <p>To explain this further, go to the definition of <code>InitializeComponent()</code> method in your (say): <code>Window1.g.cs</code> class of say: <code>WPFProject</code> project, and change its access from <code>public</code> to <code>private</code> </p> <blockquote> <p>(keep the .g.cs file open in your project otherwise the build process overrides this file, and you won't be able to see the error)</p> </blockquote> <p>Now, when you compile your WPF project, it throws a compile error as below:</p> <blockquote> <p>Error 22 'WPFProject.Window1' does not implement interface member 'System.Windows.Markup.IComponentConnector.InitializeComponent()'. 'WPFProject.Window1.InitializeComponent()' cannot implement an interface member because it is not public.</p> </blockquote> <p>Additionally, <code>InitializeComponent()</code> is marked with the <code>[System.Diagnostics.DebuggerNonUserCodeAttribute()]</code> attribute so you can't step into this method while debugging.</p> <p>There is another <a href="https://stackoverflow.com/questions/245825/what-does-initializecomponent-do-and-how-does-it-work-wpf">SO QA discussion</a>, which would help you to explain more in detail</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload