IComponentConnector interface

Applies to Windows and Windows Phone

Provides infrastructure support for event wiring and build actions.

Syntax


public interface IComponentConnector

Attributes

[Version(0x06020000)]
[WebHostHidden()]

Members

The IComponentConnector interface has these types of members:

Methods

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

MethodDescription
Connect Attaches events and names to XAML-initiated content.

 

Remarks

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 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.

Examples

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
    {
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
 
        public void Connect(int connectionId, object target)
        {
            switch(connectionId)
            {
            case 1:
                #line 21 "..\..\MainPage.xaml"
                ((Windows.UI.Xaml.Controls.Primitives.ButtonBase)(target)).Click += this.button1_Click_1;
                 #line default
                 #line hidden
                break;
            }
            this._contentLoaded = true;
        }
    }

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

XAML overview
x:Class attribute

 

 

Show:
© 2014 Microsoft