I'm using Dirkster AvalonDock(v4.60.1) with MVVM pattern in my WPF project. I would like to change the AnchorableView state into float or hide through my View Model but unfortunately there are not much examples for me to refer.
The way I did was to control the view state in a class called LayoutInitializer, which handling the LayoutUpdateStrategy for my AvalonDock.
Here is my XAML code for Avalon Dock:
<avalonDock:DockingManager.LayoutUpdateStrategy>
<helper:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>
With the above code, the XAML will create the LayoutInitializer class on its own, and through this class it is able to control the AvalonDock Elements (eg. LayoutRoot, LayoutAnchorable, Container, etc.)
Below is the code of my LayoutInitializer class to set the AnchorableView state (float or hide):
public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
{
anchorableShown.FloatingHeight = 300;
anchorableShown.FloatingWidth = 400;
anchorableShown.FloatingTop = 150;
anchorableShown.FloatingLeft = 1000;
anchorableShown.CanDockAsTabbedDocument = false;
anchorableShown.CanMove = false;
anchorableShown.CanAutoHide = true;
anchorableShown.Float();
//anchorableShown.Hide();
}
It works fine on its own, however in some cases I will need to change the AnchorableView state to Float/Hide manually through my ViewModel.
I've tried to create another new instance of LayoutInitializer class from my ViewModel, but this new created LayoutInitializer class can not access the AvalonDock Elements, and it will also result in duplicate class for LayoutInitializer.
So, How should I set the AnchorableView state from my ViewModel manually?
Q2.
<avalonDock:DockingManager.LayoutUpdateStrategy>
<helper:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>
I can think of another way to try, which is bind a property for LayoutInitializer to the XAML code.
Instead of calling
helper:LayoutInitializer/
I may bind a property of LayoutInitializer in my ViewModel with the XAML code, by this method the ViewModel can share the same object of LayoutInitializer class and my ViewModel can also change the AnchorableView state (float/hide)!
But How can I bind the LayoutInitializer from my ViewModel to the XAML code (avalonDock:DockingManager.LayoutUpdateStrategy)?
#One quick question: Does anyone still using AvalonDock for WPF, or are there other Nuget library for docking the view?
It is quite a complicated issue, sorry if my question confuse you. But I really need some help from you guys! Thanks in advance!
Solution Here is the way to bind the LayoutInitializer in the ViewModel with the View. With this method, you are able to access the AvalonDock Elements, you can freely change the state of the layout document or layout anchorable or even access to the layout root in the LayoutInitializer class.