WPF-interaction of multiple expanders and interaction of wpf-Expander
Recently I am writing some WPF controls. Let's talk about the requirements.
The product proposes to design a foldable control. When necessary, click it to display the content. If not, click collapse. In fact, the toolbox in WPF has the expander control, but there is another amazing demand: Only one expander can be expanded at a time. Similar to the radiobutton feature, you can only select one item. I searched a lot of information on the Internet and had to admire Windows as a productivity tool...
For example, the Post Bar introduces a method to integrate RadioButton with the Expander template and bind the IsChecked of RadioButton and the IsExpanded of Expander, radioButton's content and Expander's content (I have to admire Windows's development ideas ).
After F5 is run, it has both the Expander feature and the group function of RadioButton, but the header of Expander is gone ......
Someone suggested adding the Expander header to RadioButton, but it was not very detailed. Then I was just getting started, and I still couldn't do it after a long time.
Next, I found a blog where WPF simple accordion perfectly satisfies the needs, and the author proposed two ideas: Expander + listbox and one method proposed by the above post bar. The first one is slightly complicated, and the second one just mentions the following ideas. The specific implementation is not written. I don't want to use the first method. I feel that the amount of code is too large. It is most convenient to define a template and add controls directly in the xaml. No results were found for Stack Overflow for one night. This morning, I suddenly remembered the Tag attribute mentioned in this blog post, so I wanted to bind the Expander header with the Tag of RadioButton, set the Tag of RadioButton, and then run it again, the Tag property is bound to the Header of the Expander. Done ......
You need to learn more about the Template and Style in the future. It feels very esoteric and needs to be realized slowly.