C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
x:Class Attribute
WhatsApp
Dinesh Beniwal
16y
15.1
k
0
0
25
Blog
x:Class Attribute
Configures XAML compilation to join partial classes between markup and code-behind. The code partial class is defined in a separate code file in a CLR language, and the markup partial class is created by code generation during XAML compilation.
XAML Attribute Usage
<object x:Class="namespace.classname"...>
...
</object>
-or-
<object x:Class="namespace.classname;assembly=assemblyname"...>
...
</object>
XAML Values
namespace
Optional. Specifies a common language runtime (CLR) namespace that contains the partial class identified by classname. If namespace is specified, a dot (.) separates namespace and classname. If namespace is omitted, classname is assumed to have no namespace.
classname
Required. Specifies the CLR name of the partial class that connects the loaded XAML and your code-behind for that XAML.
If ;assembly=assemblyname
;assembly=assemblyname Optional. The semicolon and assembly= are literals. Specifies the assemblyname of the assembly that contains classname. is omitted, then the assembly that contains classname is assumed to be the assembly that the current project is generating.
Remarks
x:Class can be declared as an attribute for any element that is the root of a XAML file/object tree and is being compiled (where the XAML is included in a project with SilverlightPage build action), or for the Application root in the application definition of a compiled application. Declaring x:Class on any element other than a page root or application root, and under any circumstances for a XAML file that is not compiled, results 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. If x:Class is absent, then the programming model for the page defaults to the JavaScript API. If x:Class is present, the programming model for the page is the managed API. The programming models cannot be mixed on a single XAML page. The declaration of the programming model affects the resolution of event handlers when the handler names are declared as values for event attributes in the page XAML.
The value of the x:Class attribute must be a string that specifies the fully qualified name of a class. You can omit namespace information so long as that is how the code-behind is structured also (your class definition starts at the class level). The code-behind file for a page or application definition must be within a code file that is included as part of the project that produces a compiled application. You must follow name rules for CLR classes; for details, see Type Definitions. The code-behind class must be public. For more information, see Code-Behind and Partial Classes.
Note that this meaning of the x:Class attribute value is specific to the Silverlight XAML implementation. Other XAML implementations outside of Silverlight might not use managed code, and thus might use a different class resolution formula. WPF has a slightly different meaning of x:Class because WPF supports certain features that Silverlight does not, such as the ability to declare the access level of the code-behind class.
People also reading
Membership not found