Search code examples
wpfprivate

How to define a private grid in WPF


When I defined a grid in xaml and use the x:Name such as the code below,the grid seems to be "internal".I can use it just with the x:Name--'testGrid' in the same project.

    <Grid x:Name="testGrid"></Grid>

I mean that why don't define the Grid as "private",since it is "internal" then we can add/remove children to it or even can change its behaviour?Is that safe for a "sealed" class?

Thanks for your time and answers!


Solution

  • Use the FieldModifier property.

    Edit

    After reading the documentation carefully, there is no way to make a field private. It's either public (Public) or internal (NonPublic).

    So this do not answer your question...

    Anyway, you (or your team) are supposed to not intentionally mess up with your own classes, so maybe internal, while not perfect, is "good enough"?