Search code examples
c#wpfexpander

WPF MVVM prevent a Expander control to collapse


Is there a possibility to prevent a Expander control in WPF to collapse, when certain conditions are given. For my usecase it is not possible to do it directly in the xaml, because whether the Expander can be collapsed or not depends on condition just known during run time.

Its no option for me to use an event, because the project is a test project to seperate gui and code strictly.


Solution

  • Perhaps you can bind to the IsExpanded property.

    For example you can use a DataTrigger, MultiDataTrigger, ValueConverter, or MultiValueConverter to manage the data binding to the IsExpanded property.

    There's also a interesting article here that may help you.