This documentation is archived and is not being maintained.

x:ClassModifier Attribute

Modifies XAML compilation behavior in cases where x:Class is also provided. Specifically, instead of creating a partial class with a Public access level (the default), the provided x:Class is created with a NonPublic access value. This affects the access level for the class in the generated assemblies.

<object x:Class="namespace.classname" x:ClassModifier="NonPublic">


The exact string to pass to specify TypeAttributes.Public versus TypeAttributes.NotPublic varies, depending on the code-behind programming language being used. See Remarks.

x:Class must also be provided on the same element, and that element must be the root element in a page.

The value for the x:ClassModifier attribute will vary by programming language. The string to use will depend on how each language implements its CodeDomProvider and the type converters it returns to define the meanings for TypeAttributes.Public and TypeAttributes.NotPublic , and whether that language is case sensitive or not.

  • For C#, the string to pass to designate TypeAttributes.NotPublic  is internal.

  • For Microsoft Visual Basic .NET, the string to pass to designate TypeAttributes.NotPublic is Friend.

  • For C++/CLI, the C++/CLI targets do not currently support compiling XAML.

You can also specify TypeAttributes.Public (public in C#, Public in Microsoft Visual Basic .NET) but that is uncommon, because TypeAttributes.Public as the behavior is already the default.

Other values with equivalent user code access level restrictions, for example private in C#, are not relevant for x:ClassModifier, because nested class references are not supported in XAML, and thus the TypeAttributes.NotPublic modifier has the same effect.