Why would someone mark xaml with internal modifier?
Isn't internal the default access modifier for a class? Why wouldn't the same apply to xaml as it does to xaml's codebehind?
Why would someone mark xaml with internal modifier?
Isn't internal the default access modifier for a class? Why wouldn't the same apply to xaml as it does to xaml's codebehind?
The default modifier for a class is internal
. But that's a C# rule and applies only if an access modifier is not provided at all.
The XAML compiler, which generates the C# code for the object based on the XAML, by default specifies the access modifier explicitly, as public
. I.e. it uses something other than the C# language's own default. Since most if not all classes in a program need not be exposed as public
, developers often find themselves preferring to change that back to the C# default of internal
.
It's easy enough to change the *.xaml.cs
file for the code-behind, but of course there is still the auto-generated C# the XAML compiler makes, the other half of the partial
class representing that object. And of course, all partial
declarations must use the same modifier.
You can't edit the auto-generated code directly, so you have to apply the x:ClassModifier
attribute to force the XAML compiler to use the desired modifier instead of its default of public
.