-3

I am doing a school project and i can´t figure out how to "hide" some text blocks when the toggle switch is on and the opposite? Developing a windows 8 app. Thanks and btw. How do you make a collection from multiple text blocks(XAML)?

private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{

}

2 Answers2

0

Visual Studio Main Menu - Edit - Outlining - Toggle All Outlining: Ctrl+M, Ctrl+L

Personally, I use Ctrl+M to "collapse to defininitions" more than anything else though.

JonH
  • 261
  • 3
  • 12
0

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.

Community
  • 1
  • 1
GWLlosa
  • 23,995
  • 17
  • 79
  • 116
  • I'm assuming the visual studio reference in the question title is a red herring; i.e., the OP is using Visual Studio to accomplish his task, but that it is not a part of the task. – GWLlosa Apr 06 '15 at 18:33