locked
Collapse Expander control with data binding RRS feed

  • Question

  • User392993 posted

    TabbedPage with multiple ContentPages, and each ContentPage contains one or more Expander controls. What I would like to do is to collapse all Expander controls on a given ContentPage once the user switches to a different Tab, so if they return to the previous Tab all of the Expander controls will be reset to their original Collapsed state. I would like to use MVVM approach with DataBinding and NOT use CodeBehind.

    How can I accomplish this?

    Wednesday, June 3, 2020 2:59 PM

Answers

  • User369979 posted

    If you don't want to use CurrentPageChanged event of TabbedPage, you could convert it to command using: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior But if you want to collapse the control when the page reopens you could handle the OnAppearing of content page. Collapse all when it fires. Try to convert it to command too due to your requirements.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 4, 2020 8:10 AM

All replies

  • User369979 posted

    If you don't want to use CurrentPageChanged event of TabbedPage, you could convert it to command using: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior But if you want to collapse the control when the page reopens you could handle the OnAppearing of content page. Collapse all when it fires. Try to convert it to command too due to your requirements.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 4, 2020 8:10 AM
  • User392993 posted

    I haven't had time to explore the EventToCommandBehavior described in the link you provided, but it seems to be the way to go if I want to use a MVVM approach. For now I'm using the OnDisappearing event of the content page similar to what you suggested. Thanks for the help.

    Wednesday, July 8, 2020 9:07 PM