我在我的 WPF 專案中使用帶有 MVVM 模式的 Dirkster AvalonDock(v4.60.1)。我想通過我的視圖模型將AnchorableView狀態更改為浮動或隱藏,但不幸的是沒有太多示例可供我參考。
我所做的方法是在一個名為LayoutInitializer的類中控制視圖狀態,該類為我的 AvalonDock 處理LayoutUpdateStrategy。
這是我的 Avalon Dock 的 XAML 代碼:
<avalonDock:DockingManager.LayoutUpdateStrategy>
<helper:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>
通過上面的代碼,XAML 將自己創建LayoutInitializer類,并通過該類可以控制AvalonDock 元素(例如 LayoutRoot、LayoutAnchorable、Container 等)
下面是我的LayoutInitializer類設定AnchorableView狀態(浮動或隱藏)的代碼:
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();
}
它本身就可以正常作業,但是在某些情況下,我需要通過我的ViewModel手動將AnchorableView狀態更改為 Float/Hide 。
我試圖從我的ViewModel創建LayoutInitializer類的另一個新實體,但是這個新創建的LayoutInitializer類無法訪問AvalonDock Elements,它也會導致LayoutInitializer的重復類。
那么,我應該如何從我的ViewModel手動設定AnchorableView狀態?
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?
這是一個相當復雜的問題,對不起,如果我的問題讓你感到困惑。但我真的需要你們的幫助!提前致謝!
uj5u.com熱心網友回復:
解決方案這是將ViewModel 中的LayoutInitializer與View系結的方法。使用此方法,您可以訪問AvalonDock Elements,您可以自由更改布局檔案或布局可錨定的狀態,甚至可以訪問LayoutInitializer類中的布局根。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/422331.html
標籤:
