Assuming your control structure is fairly flat, you can get by using the Tag
property on the TextBox
. In your XAML, put some distinct value in the Tag
field for each TextBox
you want to make toggle-able, like the word 'CanToggle'. Then you can do something like
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
foreach (Control currentControl in this.Children)
{
if (currentControl.Tag == "CanToggle")
currentControl.Visible = !currentControl.Visible;
}
}
If your control collection is not flat, then you'll have to figure out how to dig recursively through the collection of controls to locate all the TextBox
that you want to toggle. This answer may help.