簡體   English   中英

C# WPF AvalonDock 在重新加載布局后丟失數據綁定

[英]C# WPF AvalonDock loses data binding after reloading layout

我正在使用 avalon-dock 插件,發現一個非常煩人的問題。 我的應用程序在 xamls 中使用數據綁定。 我嘗試在應用程序退出時保存 avalon-dock 的布局,並在應用程序再次啟動時加載布局(使用 XmlLayoutSerializer.Deserialize() & Serialize())。 布局被完美地保存和檢索。

但是所有數據綁定都被銷毀了,也就是說,綁定屬性的內容與應用程序上次退出時的內容保持一致,但數據綁定不再起作用。 似乎 avalon-dock 反序列化過程破壞了數據綁定,並且內容被固定在一個永久值上。

我試圖尋找為 avalon-dock 設置什么樣的布局數據來保存和檢索但沒有找到的方法。 任何機構都可以解決問題或提供一些解決方法的提示嗎?

謝謝。

這是綁定喜歡的內容(此處綁定了標題):

<avalon:LayoutAnchorable ContentId="Basic_Docu" 
CanHide="False" 
CanClose="False"
Title ="{Binding MainPageText.Basic_Tab_Title, Source={StaticResource R}}">
  <Frame Name="Basic_Docu_Frame">
  </Frame>
</avalon:LayoutAnchorable>

這是保存和檢索布局的代碼:

void Save_LayoutInfo()
{
    try
    {
        string Working_Dir = Environment.CurrentDirectory + "\\layout";
        System.IO.Directory.CreateDirectory(Working_Dir);
        XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(dockingManager);
        using (var writer = new StreamWriter(Working_Dir + "\\" + "MainPage"))
        {
            layoutSerializer.Serialize(writer);
        }
    }
    catch (Exception)
    {
        ;
    }
}

void Retrive_LayoutInfo()
{
    try
    {
        string Working_Dir = Environment.CurrentDirectory + "\\layout";
        XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(dockingManager);
        using (var reader = new StreamReader(Working_Dir + "\\" + "MainPage"))
        {
            layoutSerializer.Deserialize(reader);
        }
    }
    catch (Exception)
    {
        ;
    }
}

使用“XAML”中的LayoutItemContainerStyleSlector來維護綁定。

例如:

    <xcad:DockingManager.LayoutItemContainerStyleSelector>
        <pane:PanesStyleSelector>
            <pane:PanesStyleSelector.ToolStyle>
                <Style TargetType="{x:Type xcad:LayoutAnchorableItem}">                        
                    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}" />
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}" />
                    <Setter Property="FlowDirection" Value="RightToLeft" />
                    <Setter Property="UseLayoutRounding" Value="False" />
                    <Setter Property="IconSource" Value="{Binding Model.IconSource}" />
                    <Setter Property="IsHitTestVisible" Value="True" />
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                </Style>
            </pane:PanesStyleSelector.ToolStyle>
            <pane:PanesStyleSelector.FileStyle>
                <Style TargetType="{x:Type xcad:LayoutItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}" />
                    <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
                    <Setter Property="IconSource" Value="{Binding Model.IconSource}" />
                    <Setter Property="CanFloat" Value="{Binding Model.CanFloat}" />
                    <Setter Property="Margin" Value="5" />
                </Style>
            </pane:PanesStyleSelector.FileStyle>
        </pane:PanesStyleSelector>
    </xcad:DockingManager.LayoutItemContainerStyleSelector>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM