32

I have a user control with a ComboBox and a TextBox. Everything is working great except I noticed that from my user control's instance object, I can access those two controls. They shouldn't be accessible except via my own exposed properties.

H.B.
  • 166,899
  • 29
  • 327
  • 400
ScottG
  • 10,711
  • 25
  • 82
  • 111

1 Answers1

41

You can use the x:FieldModifier attribute on your controls, thusly:

<TextBox x:Name="textBox1" x:FieldModifier="private" />

Interestingly the MSDN page for x:FieldModifier doesn't give "private" as a valid value for the attribute, but I've tested it and it works.

Matt Hamilton
  • 200,371
  • 61
  • 386
  • 320