IComponentConnector interface

IComponentConnector interface

Provides infrastructure support for event wiring and build actions.


public interface IComponentConnector


The IComponentConnector interface has these types of members:


The IComponentConnector interface has these methods. It also inherits methods from the Object class.

Connect Attaches events and names to XAML-initiated content.



Windows 10:  Apps compiled by the XAML compiler for Windows 10 implement IComponentConnector2. Apps will fall back to IComponentConnector for compatibility if necessary.

Unless you are substantially extending the capabilities of a XAML framework or XAML design tools, you probably won't need to generate or implement IComponentConnector. The remainder of the remarks here are intended to orient you to the purpose of IComponentConnector in the Application-based app model and to explain the role of IComponentConnector in the generated code that Microsoft Visual Studio infrastructure creates as part of a typical XAML project.

By default, when you add a XAML page to a Windows Store app project in Visual Studio, its BuildAction is Page. When you build the project, all project items with that build action are processed, and code files that match the programming language choice of the project are generated. The generated code files all contain the string ".g" in their name and can be observed in the obj folder of the project after compilation. The generated files implement one part of the partial class definition that the Application-based app model uses to connect XAML and code aspects of an app definition. The process of generating partial classes from XAML is sometimes referred to as markup compilation.

Every element in XAML that has a XAML name (x:Name attribute or Name attribute applied) or an event handler declared generates a call to IComponentConnector.Connect within the generated code file. The infrastructure code for XAML build actions then defines fields that match the names on the elements. If there's event wiring done in XAML, the build actions attach the event handlers to the XAML-created instances. The fields provide the access point that both app code and infrastructure code can use to reference the object that is created as a result of parsing the XAML.

For example, if there is a XAML element for a Button named "button1" in the XAML file and it has an attribute for the Click event that references a named handler method, Visual Studio will autogenerate an implementation of Connect method from the IComponentConnector interface. The connectionId parameter is an identifier token to distinguish calls, and the target parameter is the target to connect events and names to.


The Visual Studio generated code for IComponentConnector that parallels the "button1" scenario described above might resemble the following:

partial class MainPage : Windows.UI.Xaml.Controls.Page, IComponentConnector
        public void Connect(int connectionId, object target)
            case 1:
                #line 21 "..\..\MainPage.xaml"
                ((Windows.UI.Xaml.Controls.Primitives.ButtonBase)(target)).Click += this.button1_Click_1;
                 #line default
                 #line hidden
            this._contentLoaded = true;

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Markup [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Markup [C++]





See also

XAML overview
x:Class attribute



© 2016 Microsoft