Search code examples
c#wpfavalondock

In AvalonDock how can I determine if the layout "is dirty"


I am using AvalonDock in a WPF application. I'm trying to find a nice way to determine whether the current layout "is dirty". By "is dirty" I mean the layout has changed in any way, meaning, the width of docked panels has changed, the visibility of panels has changed, etc. Basically, we want to load a named layout and flag that layout as "dirty" so the user can be alerted to save the current layout of their windows or discard that layout when the application closes.

The DocumentManager class has LayoutChanged and LayoutChanging events but those only appear to fire when a new layout is loaded -- it appears that the intention is to notify the user when the LayoutRoot of the DocumentManager gets switched out.

I believe I can use brute force by simply subscribing to PropertyChanged events on the Layout Pane ancestors, but I was hoping there was a more elegant solution.


Solution

  • As far as I know, there are no built-in solution for your requirements on AvalonDock code. That means that you have to do it manually, as you already achieved.

    In order to get your goal you need to monitor:

    1. User's resize of any AvalonDock Doc or Tool
    2. User's Hide/Show of any AvalonDock Doc or Tool
    3. User's Fload/Dock operation on any AvalonDock Doc or Tool

    The points 2. and 3. might be get by creating a base class for all your AvalonDock Docs and Tools ViewModel and handle your "is dirty" flag on FloatCommand and HideCommand.

    The point 1. could be get by placing a Grid in a base UserControl that contains all your Doc or Tool UserControls and placing a Behaviour on it linked to the Grid_SizeChanged event.

    I hope this help you.