Avalon Dock [2]:从文件重新加载布局后,无法隐藏/显示LayoutAnchorable

时间:2016-10-27 11:04:34

标签: c# wpf avalondock

我有一个简单的Avalon Dock应用程序。使用测试按钮,我可以隐藏并在代码隐藏中显示LayoutAnchorable。工作良好! 但是在将布局保存并重新加载到磁盘后,调用隐藏()/显示()将被忽略,没有例外,没有。

有什么想法吗?谢谢你的帮助!海默

这是XAML:

<Window x:Class="AvalonDockTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:AvalonDockTest" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" Title="MainWindow"
    Width="700" Height="450"
    mc:Ignorable="d">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Button x:Name="button" Width="75"
            HorizontalAlignment="Left" Click="OnTestClick"
            Content="Test" />

    <xcad:DockingManager x:Name="_dockMan" Grid.Row="1"
                         MaxHeight="425" AllowMixedOrientation="True"
                         BorderBrush="Black" BorderThickness="1"
                         Theme="{Binding ElementName=_themeCombo,
                                         Path=SelectedItem.Tag}">

        <xcad:LayoutRoot x:Name="_layoutRoot">
            <xcad:LayoutPanel Orientation="Horizontal">
                <xcad:LayoutAnchorablePane DockWidth="200">
                    <xcad:LayoutAnchorable x:Name="_layoutProp" Title="Properties"
                                           AutoHideWidth="240" CanClose="False"
                                           CanHide="False" ContentId="_idProperties">
                        <TextBlock Margin="20" Text="Properties Layout" />
                    </xcad:LayoutAnchorable>
                </xcad:LayoutAnchorablePane>

                <xcad:LayoutDocumentPaneGroup>
                    <xcad:LayoutDocumentPane>
                        <xcad:LayoutDocument Title="Document 1" ContentId="document1">
                            <Button HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Content="Document 1 Content" />
                        </xcad:LayoutDocument>
                    </xcad:LayoutDocumentPane>
                </xcad:LayoutDocumentPaneGroup>

                <xcad:LayoutAnchorablePaneGroup DockWidth="180">
                    <xcad:LayoutAnchorablePane>
                        <xcad:LayoutAnchorable Title="Alarms" ContentId="alarms">
                            <ListBox>
                                <s:String>Alarm 1</s:String>
                                <s:String>Alarm 2</s:String>
                                <s:String>Alarm 3</s:String>
                            </ListBox>
                        </xcad:LayoutAnchorable>
                    </xcad:LayoutAnchorablePane>
                </xcad:LayoutAnchorablePaneGroup>
            </xcad:LayoutPanel>

        </xcad:LayoutRoot>
    </xcad:DockingManager>
</Grid>

这就是CodeBehind:

// ---------- code behind -----
using System;
using System.Windows;
using Xceed.Wpf.AvalonDock.Layout.Serialization;

namespace AvalonDockTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Closing += MainWindow_Closing;
            LoadLayout();
        }

        private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SaveLayout();
        }

        private void OnTestClick(object sender, RoutedEventArgs e)
        {
            if (_layoutProp.IsHidden)     // toggle the LayoutAnchorable
                _layoutProp.Show();     
            else 
                _layoutProp.Hide();
        }

        private void SaveLayout()
        {
            var layoutSerializer = new XmlLayoutSerializer(_dockMan);
            layoutSerializer.Serialize("layout.xml");
        }
        private void LoadLayout()
        {
            var layoutSerializer = new XmlLayoutSerializer(_dockMan);
            layoutSerializer.Deserialize("layout.xml");
        }
    }
}

0 个答案:

没有答案