Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DockPanel不约束高度_C#_Wpf_Scrollviewer_Dockpanel - Fatal编程技术网

C# DockPanel不约束高度

C# DockPanel不约束高度,c#,wpf,scrollviewer,dockpanel,C#,Wpf,Scrollviewer,Dockpanel,我试图将DockPanel的高度限制在剩余的UserControl高度,如果它太大的话,可以使用ScrollViewer滚动 我有一个窗口,它使用ContentController来保存不同的用户控件 <Window> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Gr

我试图将DockPanel的高度限制在剩余的UserControl高度,如果它太大的话,可以使用ScrollViewer滚动

我有一个窗口,它使用ContentController来保存不同的用户控件

<Window>
<Grid>
<Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <!--  0 Menu -->
        <RowDefinition Height="auto"/>
        <!--  1 Header -->
        <RowDefinition Height="65"/>
        <!--  2 Content -->
        <RowDefinition Height="*"/>
        <!--  3 Space -->
        <RowDefinition Height="10"/>
        <!--  4 Status line -->
        <RowDefinition Height="auto"/>
        <!--  5 Space -->
        <RowDefinition Height="10"/>
    </Grid.RowDefinitions>
<!--...-->
<ContentPresenter Content="{Binding Path=MainWindowContent}" Grid.Column="0" Grid.Row="2"/>
<!--...-->
</Grid>
</Window>

我遇到麻烦的UserControl只是搜索用户和输出结果。它确实是这样的:

<UserControl>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="12"/>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="10"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="10"/>
        </Grid.RowDefinitions>

        <Grid Grid.Column="1" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <Border Grid.Column="0" Grid.Row="0">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="20"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition />
                        <ColumnDefinition Width="30"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="25"/>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="10" />
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="10"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="40"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!-- input fields -->

                    <DockPanel Grid.Column="0" Grid.Row="8" Grid.ColumnSpan="6" LastChildFill="True" VerticalAlignment="Stretch" Background="{StaticResource PrimaryCorporateBrush}">
                        <TextBlock Style="{StaticResource HeadlineOutputLabel}" DockPanel.Dock="Top"/>


                        <Separator Opacity="0" Height="10" DockPanel.Dock="Top"/>
                        <TextBlock Visibility="{Binding Path=HasResult, Converter={StaticResource Bool2RevertedVisibility}}" Margin="10" DockPanel.Dock="Top"/>
                        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding Path=HasResult, Converter={StaticResource Bool2Visibility}}">
                            <ItemsControl ItemsSource="{Binding Path=Members}" VerticalAlignment="Stretch">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Tag="{Binding}">
                                            <!-- Result Element -->
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </DockPanel>
                </Grid>
            </Border>
        </Grid>

        <Grid Grid.Column="3" Grid.Row="1">
            <!-- info display -->
        </Grid>
    </Grid>
</UserControl>

我打算将结果ScrollViewer的高度限制在窗口的剩余可见空间内,如果结果超过该高度,则显示一个滚动条。但现在DockPanel一直在扩展ScrollViewer和嵌套项控件的高度,直到所有元素都放置好,但没有显示滚动条。 我在这里有点不知所措,为什么会这样,码头板不应该将高度限制在可见空间吗?试着用按钮代替ItemsControl,没有任何东西没有滚动条。

我找到了解决方案

在网格结构中,有一行被设置为“auto”,而不是“*”,ScrollViewer似乎只能在后者中正常工作