Make a XAML file internal in .NET

10,363

You need to add a x:ClassModifier="internal" in the UserControl tag of the XAML file if you change the visibility of the class in the .cs file to internal.

The file generated from the XAML file (e.g. MyControl.g.cs) needs to match the code-behind file (e.g. MyControl.cs). x:ClassModifier allows you to control the visibility of the part declaration in the MyControl.g.cs file.

Share:
10,363
user64349
Author by

user64349

Updated on June 17, 2022

Comments

  • user64349
    user64349 almost 2 years

    In my Silverlight project, I would like to make an assembly which contains .xaml that can't be seen from outside of the assembly. However, there is no clear way I can do this. When I modify the access modifier on the .xaml.cs file, the compiler tells me:

    Partial declarations of "My xaml class here" have conflicting accessibility modifiers   
    

    In the xaml file itself, there doesn't seem to be a place to put my access modifier. In short, how do I set the class associated with my xaml file to internal?

  • Roman Starkov
    Roman Starkov over 11 years
    What they should have done is leave the partial class unmarked in the generated output, and adding "public" to the default code-behind template...