我能用滚动浏览器做什么?

时间:2013-01-11 10:20:52

标签: wpf wpf-controls scrollview

  • 我在其中使用了一个带有scrollviewer的GroupBox ..在scrollviewer里面我放了一个网格并开始放置我的控件(3个文本块和7个文本框)
  • 我不能让滚动查看器滚动我的内容..我不知道我是否想念一些东西来激活它
  • 这是我的xaml代码:

      <GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="363,20,38,486" Name="groupBox1" VerticalAlignment="Stretch" Panel.ZIndex="0">
                        <ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
                            <Grid Name="grid1" Height="132">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="2*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
                                <TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
                                <TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
                                <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
                            </Grid>
                        </ScrollViewer>
                    </GroupBox>
    

2 个答案:

答案 0 :(得分:1)

我稍微修改了你的代码

 <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="1,0,0,129" Name="groupBox1" VerticalAlignment="Stretch" Grid.Column="1" Grid.RowSpan="3">
       <ScrollViewer Name="scrollViewer1" Width="Auto"  VerticalScrollBarVisibility="Visible" >
            <Grid  Name="grid1" Width="376" Height="280">
                <TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto"  Name="textBlock4" Padding="0" Text="Generic ID" TextAlignment="Right" Margin="-20,0,20,0" />
                <TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto"  Name="textBlock5" Padding="0" Text="Generic Name" TextAlignment="Right" Margin="-10,20,10,-20" />
                <TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto"  Name="textBlock6" Padding="0" Text="Other Names" TextAlignment="Right" Margin="-15,43,15,-43" />
                <TextBox Height="25" Name="textBox8" Width="225" Margin="22,199,130,44" />
                <TextBox Height="25"  Name="textBox9" Width="225" Margin="20,147,131,95" />
                 <TextBox Height="25" Name="textBox11" Width="225" Margin="20,97,131,159" />
                <TextBox Height="25"  Name="textBox12" Margin="21,122,131,121" />
                <TextBox Height="25"  Name="textBox13" Width="225" Margin="20,159,131,52" />
                <TextBox Height="25"  Name="textBox14" Width="225" Margin="20,222,131,20" />
            </Grid>
        </ScrollViewer>
    </GroupBox>

</Grid>

试试这是否成功。我认为边距和高度导致了问题

答案 1 :(得分:1)

尝试设置GroupBox的高度。它正在伸展以填充整个窗口,您的内容将延伸至Fit。如果限制GroupBox的大小,您将获得VerticalScroll,它将起作用。我修改了你的代码并且它可以工作:

<GroupBox BorderBrush="#FF0000DD" FontSize="13"  FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch"  Height="132" Name="groupBox1"  Panel.ZIndex="0">
    <ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
        <Grid Name="grid1" Height="132">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
            <TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
            <TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
            <TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
        </Grid>
    </ScrollViewer>
</GroupBox>

结果如下:

enter image description here