为什么我的dockpanel的LastChild溢出其容器?

时间:2013-03-05 19:14:34

标签: wpf listview dockpanel

我有一个DockPanel,LastChildFill = true。它有4个子节点:StackPanel(顶部),另一个DockPanel(顶部),以及另外三个StackPanel(分别为bottom,left和none)。最后一个StackPanel(“ResultsPanel”)没有设置DockPanel.Dock属性,也没有宽度/高度,但是当数据绑定导致的行数多于屏幕上适合的行数时,它会继续向下停靠在底部停靠的StackPanel之后。我希望它能填补我留在其他停靠儿童之间的中心“洞”。

如果我将ScrollBarVisibilities设置为Auto,它甚至不会显示它们。任何意见,将不胜感激。以下是相关代码:

   <DockPanel Name="JobsDock" LastChildFill="True">
<StackPanel DockPanel.Dock="Top" Height="40"  >
    <Label />
    <Border CornerRadius="5" Width="90" Height="25" >
        <Label Content="Classic View" />
    </Border>
</StackPanel>
<DockPanel DockPanel.Dock="Top" Height="70" Name="SearchJobsPanel" >
    <ComboBox Name="SearchOptionComboBox" VerticalAlignment="Bottom" Width="240"  />
    <StackPanel Height="50" Name="JobPanel" Width="90" Visibility="Collapsed" VerticalAlignment="Bottom" >
        <Label Content="Job Number" HorizontalAlignment="Center" />
        <TextBox Name="JobTextBox" />
    </StackPanel>   
    <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right">
        <Button Height="25" Name="SearchButton" Width="90">
            <StackPanel Orientation="Horizontal">
                <Image  Stretch="Fill" Margin="0,0,5,0" />
                <Label Content="Search" FontSize="10" VerticalContentAlignment="Top"  />
            </StackPanel>
        </Button>
   </StackPanel>
</DockPanel>
<StackPanel  Name="FiltersPanel" DockPanel.Dock="Left" Width="120" Opacity="0" >
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <Button Name="ResetFilterButton" >
            <Image Source="Images/ResetFilter.png" Width="30"  />
        </Button>
        <Button Name="ApplyFilterButton"  >
            <Image Width="30"  />
        </Button>                    
    </StackPanel>
    <Label Name="ProjectsLabel"  />
    <Label Name="TasksLabel"  Margin="0,10,0,0" />
</StackPanel>
<StackPanel Name="ResultsPanel" Opacity="0">
    <ListView x:Name="DisplayedJobListView" ScrollViewer.VerticalScrollBarVisibility="Visible" >
        <ListView.View>
            <GridView>
            </GridView>
        </ListView.View>
    </ListView>
</StackPanel>

1 个答案:

答案 0 :(得分:1)

Jurgen,在msdn论坛上回答了这个问题。以下是他的回复:

您好,

最后一个(填充)DockPanel子节点是StackPanel(“ResultsPanel”)。 StackPanel的布局永远不会通过包含控件来定义(对于StackPanel,没有像VerticalLayout =“Stretch”那样工作)。它将始终占用空间,因为它包含的控件可以完全展开。

由于StackPanel中只有一个子节点(它具有自己的滚动机制),所以删除StackPanel。

希望这有帮助。

干杯 尔根

相关问题