Multiple Expander have to collapse if ONE is expanded

前端 未结 7 981
南笙
南笙 2020-12-08 22:42

Having 4 Expander controls. When one expander is expanded how can I make all others collapse/close?

相关标签:
7条回答
  • 2020-12-08 23:47

    I also needed this, but all answers was too much work IMO. Here is how I did it:

    1. added StackPanel (child align is set to vertical).
    2. added 3 Expanders into it. (needed 3)
    3. set height of Expanders to 120px to add elements to it.
    4. each Expander called ex1..3.
    5. each one got 2 events

      private void ex1_Collapsed(object sender, RoutedEventArgs e)  
      {  
          ex1.Height = 23.0;  
      }  
      
      private void ex1_Expanded(object sender, RoutedEventArgs e)    
      {  
          ex1.Height = 120.0;  
          ex2.IsExpanded = false;  
          ex3.IsExpanded = false;  
      }  
      
    6. reset all the Expanders that should be collapsed height back to 23px at window_loaded.

    that it.

    0 讨论(0)
提交回复
热议问题