Search code examples
wpfxamlavalondock

AutoHideWidth for AvalonDock


I Have an AvalonDock 2 with LayoutAnchorablePane like below,

     <xcad:DockingManager
                     AnchorablesSource="{Binding AnchorableSource}" 
                     DocumentsSource="{Binding DocumentSource}" 
                     Utility:AvalonDockLayoutSerializer.LoadLayoutCommand="{Binding LoadLayoutCommand}"
                     Utility:AvalonDockLayoutSerializer.SaveLayoutCommand="{Binding SaveLayoutCommandOnExit}">
    <xcad:DockingManager.Theme>
        <xcad:MetroTheme />
    </xcad:DockingManager.Theme>
    <xcad:DockingManager.LayoutUpdateStrategy>
        <Pane:LayoutInitializer/>
    </xcad:DockingManager.LayoutUpdateStrategy>
    <xcad:DockingManager.Resources>            
        <DataTemplate DataType="{x:Type ViewModels:ExplorerViewModel}">
            <Views:ExplorerView />
        </DataTemplate>            
        <DataTemplate DataType="{x:Type ViewModels:TableOfContentViewModel}">
            <Views:TableOfContentView x:Name="TOCView" Focusable="True">
                <Views:TableOfContentView.InputBindings>
                    <KeyBinding Key="F5" Command="{Binding GridF5Command}"/>
                </Views:TableOfContentView.InputBindings>
            </Views:TableOfContentView>
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:PropertyViewModel}">
            <Views:PropertyView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:SearchViewModel}">
            <Views:SearchPanel />
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:DocumentViewModel}">
            <Views:DocumentView />
        </DataTemplate>    
    </xcad:DockingManager.Resources>       
    <xcad:DockingManager.LayoutItemContainerStyleSelector>
        <Pane:PanesStyleSelector>
            <Pane:PanesStyleSelector.ToolStyle>
                <Style TargetType="{x:Type xcad:LayoutAnchorableItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}"/>
                    <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="LeftToRight"/>
                    <Setter Property="UseLayoutRounding" Value="False"/>
                </Style>
            </Pane:PanesStyleSelector.ToolStyle>
            <Pane:PanesStyleSelector.FileStyle>
                <Style TargetType="{x:Type xcad:LayoutItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}"/>
                    <Setter Property="ToolTip" Value="{Binding Model.FilePath}"/>
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                    <Setter Property="CanClose" Value="False"/>
                </Style>
            </Pane:PanesStyleSelector.FileStyle>
        </Pane:PanesStyleSelector>
    </xcad:DockingManager.LayoutItemContainerStyleSelector>
    <xcad:LayoutRoot>
        <xcad:LayoutPanel Orientation="Horizontal">
            <xcad:LayoutAnchorablePane Name="Explorer" DockMinWidth="200" FloatingWidth="200"/>
            <xcad:LayoutAnchorablePane Name="TOC" DockMinWidth="630"/>
            <xcad:LayoutAnchorablePaneGroup Orientation="Vertical" DockMinWidth="300">
                <xcad:LayoutAnchorablePane Name="Property" />
                <xcad:LayoutAnchorablePane Name="Search" />
            </xcad:LayoutAnchorablePaneGroup>
            <xcad:LayoutDocumentPane>                    
            </xcad:LayoutDocumentPane>
        </xcad:LayoutPanel>            
    </xcad:LayoutRoot>
</xcad:DockingManager>

How do i set the AutoHideMinWidth and AutoHideMinHeight for my LayoutAnchorable.


Solution

  • Unfortunantly neither of LayoutAnchorable or LayoutAnchorablePane are a FramworkElement so you can't apply a global style to set the AutoHideMinWidth and AutoHideMinHeight properties, your only option here is to download the AvalonDock 2.0 source code : http://avalondock.codeplex.com/SourceControl/latest#Version2.0/

    Add and reference the project to your solution. Under Xceed.Wpf.AvalonDock project /Layout/LayoutAnchorable.cs, update the AutoHideMinWidth and AutoHideMinHeight default values to what suits you best.

        #region AutoHideMinWidth
    
        private double _autohideMinWidth = 100.0; //default value
        public double AutoHideMinWidth
        {
            get { return _autohideMinWidth; }
            set
            {
                if (_autohideMinWidth != value)
                {
                    RaisePropertyChanging("AutoHideMinWidth");
                    if (value < 0)
                        throw new ArgumentException("value");
                    _autohideMinWidth = value;
                    RaisePropertyChanged("AutoHideMinWidth");
                }
            }
        }