title | description | ms.date | ms.custom | f1_keywords | helpviewer_keywords | ms.assetid | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
x:ClassModifier Directive |
Learn about the x:ClassModifier Directive. |
03/30/2017 |
devdivchpfy22 |
|
|
ef30ab78-d334-4668-917d-c9f66c3b6aea |
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.
<object x:Class="namespace.classname" x:ClassModifier="NotPublic">
...
</object>
Value | Description |
---|---|
NotPublic | The exact string to pass to specify xref:System.Reflection.TypeAttributes.Public?displayProperty=nameWithType versus xref:System.Reflection.TypeAttributes.NotPublic?displayProperty=nameWithType 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 6.3.1.8.
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 xref:System.CodeDom.Compiler.CodeDomProvider and the type converters it returns to define the meanings for xref:System.Reflection.TypeAttributes.Public?displayProperty=nameWithType and xref:System.Reflection.TypeAttributes.NotPublic?displayProperty=nameWithType, and whether that language is case sensitive.
-
For C#, the string to pass to designate xref:System.Reflection.TypeAttributes.NotPublic?displayProperty=nameWithType is
internal
. -
For Microsoft Visual Basic .NET, the string to pass to designate xref:System.Reflection.TypeAttributes.NotPublic?displayProperty=nameWithType is
Friend
. -
For C++/CLI, no targets exist that support compiling XAML; therefore, the value to pass is unspecified.
You can also specify xref:System.Reflection.TypeAttributes.Public?displayProperty=nameWithType (public
in C#, Public
in Visual Basic); however, specifying xref:System.Reflection.TypeAttributes.Public?displayProperty=nameWithType is infrequently done because xref:System.Reflection.TypeAttributes.Public?displayProperty=nameWithType 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 xref:System.Reflection.TypeAttributes.NotPublic?displayProperty=nameWithType modifier has the same effect.
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.