简体   繁体   中英

How to create AvalonDock LayoutInitializer in ViewModel and bind it to the XAML code?

I'm using Dirkster AvalonDock(v4.60.1) with MVVM pattern.

Avalon Dock usually setup the LayoutUpdateStrategy as below: (In XAML)

<avalonDock:DockingManager.LayoutUpdateStrategy>
    <helper:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>

However, I need to change the anchorable view to Float/Hide manually through my ViewModel, therefore the way I think can be done is to create the LayoutInitializer class in my ViewModel and bind it to the XAML in order for my ViewModel to access the AvalonDock Element(eg. LayoutRoot, LayoutAnchorable, Container, etc.).

How can I create the LayoutInitializer class in my ViewModel and bind it to <avalonDock:DockingManager.LayoutUpdateStrategy> in XAML?

Beating my head against the wall for the entire week and I forgot to try the simplest binding method.

Thanks to @Lei Yang, for reminding me (at the comment section):

Since I can create the helper:LayoutInitializer over my ViewModel , then obviously I can bind my entire DockingManager.LayoutUpdateStrategy to that created helper:LayoutInitializer class.

Instead of writing the XAML code to create that helper:LayoutInitializer class:

<avalonDock:DockingManager.LayoutUpdateStrategy>
    <helper:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>

I can bind it over the Docking Manager ,

<avalonDock:DockingManager x:Name="dockManager"
                                   AnchorablesSource="{Binding TVm}"
                                   DocumentsSource="{Binding CVM}"
                                   ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
                                   Background="WhiteSmoke"
                                   LayoutUpdateStrategy="{Binding ADLayoutStrategy}">...

Above code does the magic, as you can see the last row of the avalonDock:DockingManager . I bind the LayoutUpdateStrategy to a property of my ViewModel and that property is pointing to my helper:LayoutInitializer class.

LayoutInitializer ADLayoutStrategy = new LayoutInitializer();

Now, the ViewModel can access the UIElement and change the document/anchorable view state!

I don't know is there anyone still using AvalonDock out there, but hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM