0

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?

Liger86
  • 57
  • 1
  • 8
  • Check out the *actual* access modifier on the generated codebehind class and corresponding partial - see http://stackoverflow.com/questions/3957576/how-to-change-the-access-modifier-of-a-user-control – user2864740 Mar 15 '15 at 06:44

1 Answers1

0

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.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136