How do I create a collapsible section? That is, a section that can show/hide child controls, whether they are required or not. I can’t use an optional section, because it requires binding.
The easiest way to do this is to this is using Conditional Formatting. Select the Section control, then pick Format | Conditional Formatting…. Add a rule where the formatting is “Hide this control”.
We often call this “conditional visibility.” Like everything in InfoPath, the view state is driven entirely by the data, so you need something in your data which maps to the expand/collapse state. One common approach is to add an attribute field to the group element the section is bound to. It shows up in your data when saved, and the expand/collapse state is saved when users save the form.
Bind a checkbox to the attribute, and you now have UI which lets the user control the state. If you prefer a button, you can create a rule which sets the value of the attribute; use two buttons with more conditional visibility rules to swap the label (e.g. between a + and a – to look like a TreeView). You can also write code which modifies the value of the attribute, and the section will show or hide.