WPF-interaction of multiple expanders and interaction of wpf-Expander

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.