Compartir a través de


x:Class Attribute

Configures XAML compilation in order to link the root element of a XAML page to a partial class defined in a separate code file in a Common Language Specification (CLS) language that provides code-behind logic for that page.

XAML Attribute Usage

<object x:Class="namespace.classname"...>
  ...
</object>

XAML Values

namespace

Optional. Specifies a CLR namespace that contains the partial class identified by classname. If namespace is specified, a dot (.) separates namespace and classname.

classname

Required. Specifies the CLR name of the partial class that connects the loaded XAML and your code-behind for that XAML.

Remarks

x:Class can be declared for any element that is the root of a Extensible Application Markup Language (XAML) element tree (where the Extensible Application Markup Language (XAML) is included in a project with Page build action), or for the Application root in the application definition. Declaring x:Class on any element other than a page root or application root will result in a compile-time error.

The class used as x:Class cannot be a nested class.

x:Class is optional in the sense that is it is entirely legal to have a XAML page with no code-behind at all, but if your page declares event handling attribute values, or instantiates custom elements where the defining classes are in the code-behind class, providing the x:Class reference (or x:Subclass) to the appropriate class for code-behind is ultimately required.

The value of the x:Class attribute can be any string that specifies the fully qualified name of aclass, as defined in a code-behind file that is included as part of the project that produces the application. You must follow name rules for CLR classes; for details, see Type Definitions. By default, this class must be public, but can be defined to be a different access level by using the x:ClassModifier Attribute.

See Also

Reference

x:Subclass Attribute
x:ClassModifier Attribute

Concepts

XAML and Custom Classes
Code-Behind and XAML