x:ClassModifier Directive

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

XAML Attribute Usage

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

XAML Values

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


x:Class must also be provided on the same element, and that element must be the root element in a page. For more information, see [MS-XAML] Section


The value of x:ClassModifier in .NET XAML Services usage varies by programming language. The string to use depends 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.

  • 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, no targets exist that support compiling XAML; therefore, the value to pass is unspecified.

You can also specify TypeAttributes.Public (public in C#, Public in Visual Basic); however, specifying TypeAttributes.Public is infrequently done because TypeAttributes.Public is already the default behavior.

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

Security Notes

The access level as declared in x:ClassModifier is still subject to interpretation by particular frameworks and their capabilities. WPF includes capabilities to load and instantiate types where x:ClassModifier is internal, if that class is referenced from a WPF resource through a pack URI reference. As a consequence of this case and potentially others like it implemented by other frameworks, do not rely exclusively on x:ClassModifier to block all possible instantiation attempts.

See also