2

我是 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>

4

2 回答 2

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>

始终使用 Auto 或 Start 网格长度进行子控件的动态布局排列,

阿多

于 2012-12-12T11:36:58.230 回答
0

我知道这很旧,但我也花了一段时间才弄清楚这一点(带有 .NET 4.5 的 WPF 上的 AD 2.0),所以我会为可能将其用作源的其他人发布。adospace 的答案是有效的。但是,您还必须更改您的代码。

消除 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">
于 2015-01-07T08:21:56.293 回答