How to Stretch / Enlarge AvalonDock DocumentPane

I am using AvalonDock v 1.3 on .NET 3.5.

I added two document panels at design time for the DockingManager. The first one should be visible, and the second one is hidden / compensated (see "Visibility =" Collapsed "below).

When I launch the application, the second document panel is not visible, which is the intended behavior, but, unfortunately, the visible document panel does not appear stretched around the edges of the main window, although the HorizontalAlignment parameter is set to "Stretched". How can I make this clip (or maximize) along the edges of the allowed area?

This is the xaml I use:

<ad:DockingManager x:Name="dockManager" Grid.Row="1"> <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal"> <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" > <ad:DocumentContent Title="A"/> <ad:DocumentContent Title="B"/> </ad:DocumentPane> <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed"> <ad:DocumentContent Title="A"/> <ad:DocumentContent Title="B"/> </ad:DocumentPane> </ad:ResizingPanel> </ad:DockingManager> 

Thanks Dave

As requested, here is the full XAML:

  <Window x:Class="AvalonDockSampleProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock" Title="MainWindow" Height="421" Width="948"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="24"/> <RowDefinition Height="*"/> <RowDefinition Height="24"/> </Grid.RowDefinitions> <Menu> <MenuItem Header="File"> <MenuItem Header="Create DockableContent" Click="CreateDockableContent"/> <MenuItem Header="Layout"> <MenuItem Header="Save" Click="SaveLayout"/> <MenuItem Header="Restore" Click="RestoreLayout"/> </MenuItem> <MenuItem Header="Exit"/> </MenuItem> </Menu> <ad:DockingManager x:Name="dockManager" Grid.Row="1"> <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal"> <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" > <ad:DocumentContent Title="A!"/> <ad:DocumentContent Title="B!"/> </ad:DocumentPane> <ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed"> <ad:DocumentContent Title="A"/> <ad:DocumentContent Title="B"/> </ad:DocumentPane> </ad:ResizingPanel> </ad:DockingManager> <StatusBar Grid.Row="2"> <StatusBarItem Content="AvalonDock 1.3 Sample Project"/> </StatusBar> </Grid> </Window> 
+4
source share
1 answer

You are right, it seems difficult to define your collapsedDocumentPane in XAML, since AvalonDoc reserve a place for it (tab header or something else), completely ignoring Visibility="Collapsed" , so I ended up adding / removing mine in the code. So:

First, remove your "collapsedDocumentPane" from XAML (I comment on it so that it can be used as a link from the following code):

 <ad:DockingManager x:Name="dockManager" Grid.Row="1"> <ad:ResizingPanel Name="resizePanel" Orientation="Horizontal"> <ad:DocumentPane Name="visibleDocumentPane" HorizontalAlignment="Stretch" > <ad:DocumentContent Title="A"/> <ad:DocumentContent Title="B"/> </ad:DocumentPane> <!--<ad:DocumentPane Name="collapsedDocumentPane" Visibility="Collapsed"> <ad:DocumentContent Title="A"/> <ad:DocumentContent Title="B"/> </ad:DocumentPane>--> </ad:ResizingPanel> </ad:DockingManager> 

And recreated that xaml in the code behind (in your xaml.cs file):

 private DockablePane _collapsedDocumentPane; private DockablePane CollapsedDocumentPane { get { if (_collapsedDocumentPane== null) { _collapsedDocumentPane= new DockablePane(); var a = new DockableContent { Title = "A", DataContext = _youViewModel, //if you pass data context DockableStyle = DockableStyle.AutoHide, Content = new RadGridView(), //just a sample control }; var b = new DockableContent { Title = "B"}; _collapsedDocumentPane.Items.Add(a); _collapsedDocumentPane.Items.Add(b); } return _errorsDockablePane; } } 

Then a method that adds or removes it:

 private void EvaluateCollapsedDocPaneVisibility() { //don't know your scenario if (NeedToDisplay_CollapsedDocPane) { if (!resizePanel.Children.Contains(CollapsedDocumentPane)) resizePanel.Children.Add(CollapsedDocumentPane); } else { if (resizePanel.Children.Contains(CollapsedDocumentPane)) resizePanel.Children.Remove(CollapsedDocumentPane); } } 

Note that the lazy property is loaded - built only when necessary. So now all you have to do is call the method above when you need to add or remove. This is just a sample, you can add an argument to the method to tell him what to do, or something else, hope this helps / helps you.

0
source

Source: https://habr.com/ru/post/1381397/


All Articles