它不显示滚动?

时间:2014-05-21 07:49:01

标签: c# wpf

在这段代码中,我想把滚动条放在那里,因为我做了那个,但它没有显示滚动。

   <ScrollViewer VerticalScrollBarVisibility="Visible"   HorizontalScrollBarVisibility="Visible">
<Grid Width="387" Height="186" Background="LightBlue"  >

        <TextBox Height="110" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="6,6,0,0"  Name="textBox1" VerticalAlignment="Top" Width="375" />
        <TextBox Height="110" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="6,122,0,0"   Name="textBox2" VerticalAlignment="Top" Width="375" Grid.RowSpan="2" />
    </Grid>
</ScrollViewer>

1 个答案:

答案 0 :(得分:0)

在您的示例中,具有LightBlue颜色的网格是容器控件,并且具有2个子文本框。您已限制此网格的HeightWidth,该网格需要ScrollBar才能查看子控件(此处为文本框)。因此,您需要将ScrollBar保留在父Grid内(LightBlue颜色网格)。请更改您的XAML,如下所示,以启用横向和纵向ScrollBars

<Grid Width="387"
          Height="186"
          Background="LightBlue">
        <ScrollViewer VerticalScrollBarVisibility="Visible"
                      HorizontalScrollBarVisibility="Visible">
            <Grid>
                <TextBox Height="110"
                         HorizontalAlignment="Left"
                         TextWrapping="Wrap"
                         Margin="6,6,0,0"
                         Name="textBox1"
                         VerticalAlignment="Top"
                         Width="375" />
                <TextBox Height="110"
                         HorizontalAlignment="Left"
                         TextWrapping="Wrap"
                         Margin="6,122,0,0"
                         Name="textBox2"
                         VerticalAlignment="Top"
                         Width="375"
                         Grid.RowSpan="2" />
            </Grid>
        </ScrollViewer>
    </Grid>