确定Scrollviewer?

时间:2013-09-05 09:06:30

标签: c# wpf wpf-controls

使用此代码我想看到200x200窗口有3个项目。带有滚动条的第二个或中间项目,在最大化窗口时无法拉伸到它的全尺寸。 “当窗口处于正常状态时,我忘了告诉我想要那个具有精确高度尺寸的滚动查看器(例如120 *)。如果窗口被拉伸,那么我想用它的”自动“尺寸拉伸所有项目(意味着我想要的显示滚动查看器的项目。)“怎么解决?

<Title="Window1" Height="200" Width="200">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBox Grid.Row="0" Text="Hi" VerticalAlignment="Center"/>
        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBox Grid.Row="0" Text="HI"  VerticalAlignment="Center"/>
                <TextBox Grid.Row="1" Text="HI" VerticalAlignment="Center"/>
                <TextBox Grid.Row="2" Text="HI" VerticalAlignment="Center"/>
                <TextBox Grid.Row="3" Text="HI" VerticalAlignment="Center"/>
            </Grid>
        </ScrollViewer>
        <TextBox Grid.Row="2" Text="Hello&#10;Hello&#10;Hello&#10;"/>
    </Grid>

请看这张图片:

enter image description here

或者转到http://i42.tinypic.com/10r7994.png查看完整尺寸的图片。

2 个答案:

答案 0 :(得分:0)

尝试Height="*"将剩余空间用于中间项:

<Grid.RowDefinitions>
    <RowDefinition Height="50" />
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

答案 1 :(得分:0)

您应该设置ScrollViewer的MinHeight和MinWidth。 并使用Element绑定窗口高度和宽度的ScrollViewer的高度和宽度。

Like-- MinHeight =“120”MinWidth =“120”
高度=“{绑定路径=高度,ElementName =风}”

Width =“{Binding Path = Width,ElementName = Wind}”

它应该有用。

相关问题