我是WPF新手并开始使用Avalon Dock。我的工具栏有问题。当我在工具栏托盘中拖动工具栏托盘得到扩展并卡在Avalon Dock容器后面。我如何让它自动重新调整大小以便工具栏不会卡在后面?这是我的XAML ..谢谢:)
<Window x:Class="PSWPF0._001.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonDock="http://avalondock.codeplex.com"
Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="381" d:DesignWidth="754" SizeToContent="WidthAndHeight">
<Grid DataContext="{Binding}" AllowDrop="True" ClipToBounds="True" IsItemsHost="False">
<DockPanel HorizontalAlignment="Stretch" Margin="2,0,0,0" Name="dockPanel1" VerticalAlignment="Stretch" />
<Menu Height="22" HorizontalAlignment="Stretch" Name="menu1" VerticalAlignment="Top" Margin="2,0,-2,0" DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="New" Click="MenuItem_Click_4">
<MenuItem Header="Project" />
<MenuItem Header="C Source File" />
<MenuItem Header="Text File" />
</MenuItem>
<MenuItem Header="Open" Click="MenuItem_Click_5"/>
<MenuItem Header="Save" />
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Undo" />
<MenuItem Header="Redo" />
<Separator />
<MenuItem Header="Copy" />
<MenuItem Header="Cut" />
<MenuItem Header="Paste" />
<MenuItem Header="Delete" />
<Separator />
<MenuItem Header="Find" />
</MenuItem>
<MenuItem Header="View" Click="MenuItem_Click_1">
<MenuItem Header="Project Dashboard"/>
<MenuItem Header="Project Explorer" />
</MenuItem>
<MenuItem Header="Help" Click="MenuItem_Click">
<MenuItem Header="About" Click="MenuItem_Click_3"/>
<MenuItem Command="ApplicationCommands.Help" Header="Help Content" />
</MenuItem>
</Menu>
<ToolBarTray DockPanel.Dock="Top" Background="LightGray" VerticalAlignment="Top" Margin="2,23,-2,0">
<ToolBar Band="1" BandIndex="1">
<Button>New</Button>
<Button>Open</Button>
<Button>Exit</Button>
</ToolBar>
<ToolBar BandIndex="2" Band="2">
<Button>Undo</Button>
<Button>Redo</Button>
</ToolBar>
<ToolBar Band="2" BandIndex="2">
<Button>Paint</Button>
<Button>Spaell</Button>
<Separator />
<Button>Cut</Button>
<Button>Copy</Button>
<Button>Paste</Button>
<Separator />
<Button>Find</Button>
<Button>Replace</Button>
</ToolBar>
</ToolBarTray>
<avalonDock:DockingManager x:Name="dockingManager" Margin="0,52,0,28" VerticalAlignment="Stretch" DockPanel.Dock="Top" Grid.Column="0" AllowMixedOrientation="True" IsManipulationEnabled="False" UseLayoutRounding="True">
<avalonDock:LayoutRoot>
<avalonDock:LayoutPanel Orientation="Vertical">
<avalonDock:LayoutDocumentPaneGroup DockMinHeight="70">
<avalonDock:LayoutDocumentPane>
<avalonDock:LayoutDocument Title="Doc1">
<TextBox/>
</avalonDock:LayoutDocument>
<avalonDock:LayoutDocument Title="Doc2">
<TextBox/>
</avalonDock:LayoutDocument>
</avalonDock:LayoutDocumentPane>
<avalonDock:LayoutDocumentPane >
</avalonDock:LayoutDocumentPane>
</avalonDock:LayoutDocumentPaneGroup>
<avalonDock:LayoutAnchorablePaneGroup IsMaximized="True" DockMinHeight="70" DockHeight="250">
<avalonDock:LayoutAnchorablePane>
<avalonDock:LayoutAnchorable Title="Output">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Error List">
<TextBox/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorablePane>
</avalonDock:LayoutAnchorablePaneGroup>
</avalonDock:LayoutPanel>
<avalonDock:LayoutRoot.RightSide>
<avalonDock:LayoutAnchorSide>
<avalonDock:LayoutAnchorGroup>
<avalonDock:LayoutAnchorable Title="Properties" AutoHideMinWidth="200">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Project Explorer" AutoHideMinWidth="200">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="File Explorer" AutoHideMinWidth="200">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorGroup>
</avalonDock:LayoutAnchorSide>
</avalonDock:LayoutRoot.RightSide>
<avalonDock:LayoutRoot.LeftSide>
<avalonDock:LayoutAnchorSide>
<avalonDock:LayoutAnchorGroup>
<avalonDock:LayoutAnchorable Title="Project Dashboard" AutoHideMinWidth="200">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Hardware Toolbox" IsMaximized="True" CanAutoHide="True" IsActive="True" AutoHideMinWidth="200">
<ListBox/>
</avalonDock:LayoutAnchorable>
<avalonDock:LayoutAnchorable Title="Logic Building Blocks" AutoHideMinWidth="200">
<RichTextBox/>
</avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorGroup>
</avalonDock:LayoutAnchorSide>
</avalonDock:LayoutRoot.LeftSide>
</avalonDock:LayoutRoot>
</avalonDock:DockingManager>
<StatusBar Height="22" HorizontalAlignment="Stretch" Margin="2,322,0,0" Name="statusBar1" VerticalAlignment="Bottom" DockPanel.Dock="Bottom"/>
</Grid>
答案 0 :(得分:2)
我建议使用这样的动态布局:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>//<-- for menu
<RowDefinition Height="Auto"/>//<-- for toolbar
<RowDefinition Height="*"/>//<-- for docking manager
<RowDefinition Height="Auto"/>//<-- for status bar
</Grid.RowDefinitions>
</Grid>
始终使用自动或开始网格长度来进行子控件的动态布局安排
腺苷
答案 1 :(得分:0)
我知道这已经过时了但我花了一段时间来解决这个问题(使用.NET 4.5的WPF上的AD 2.0)所以我会发布其他人可能会将其用作源代码。广告的答案是有效的。但是,您也必须更改代码。
消除DockingManager的上边距,除非您有其他需要。我的布局看起来很奇怪,直到我意识到在使用网格RowDefinitions
之前我仍然有一个上边距设置。此外,请从菜单中删除DockPanel.Dock="Top"
,除非您还有其他内容。我没有VerticalAlignment
设置。
在这里,我所得到的效果很好,包括多个乐队。使用其中一个AD测试应用程序,它已经具有根网格(gdlayoutRoot),因此您可以使用该网格。
<Grid Name="gdlayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Menu IsMainMenu="True" Name="menuMain" Grid.Row="0">
<MenuItem Header="_File" Name="File">
<MenuItem Header="_New" Name="New" />
</MenuItem>
<MenuItem Header="_Edit" Name="Edit" />
<MenuItem Header="_Document" Name="Document">
<MenuItem Header="Import From _XML">
<MenuItem Header="Entity" Name="ImportFromXML" Click="ImportFromXML_Click" />
</MenuItem>
</MenuItem>
</Menu>
<ToolBarTray Grid.Row="1">
<ToolBar Band="0" BandIndex="0">
<Button Content="Stuff"/>
</ToolBar>
</ToolBarTray>
<ad:DockingManager x:Name="dockingManager" Grid.Row="3">