Is it possible to prevent a XAML element with an x:Name from being accessible outside of the class in which it is defined?
Say I have a control with a label, and I want to be able to reference that label from code-behind. I can accomplish this by giving the label an x:Name
:
<UserControl x:Class=...>
<Label x:Name="someLabel">Foo</Label>
....
</UserControl>
Unfortunately, now I can do this in a different class:
`someUserControl.someLabel.Content = ...`
Is there any way to limit access to the Label
to the class in which it is defined? I.e., I would still be able to reference开发者_运维知识库 it in the UserControl's code-behind, but nowhere else.
By default they will be internal, and the documentation says you can use the x:FieldModifier attribute to make it public. Regardless of what the docs say, you can do x:FieldModifier="private"
for C# to make the field private.
精彩评论