- 我使用了一个 GroupBox,里面有一个滚动查看器。在滚动查看器里面我放了一个网格并开始放置我的控件(3 个文本块和 7 个文本框)
- 我不能让scrollviewer滚动我的内容..我不知道我是否错过了激活它的东西
这是我的 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>
问问题
654 次
2 回答
2
尝试设置您的 GroupBox 的高度。它正在拉伸以填充整个窗口,并且您的内容正在拉伸以适应。如果您限制 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>
结果是:
于 2013-01-12T20:01:16.513 回答
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>
试试这是否可行。我认为边距和高度是导致问题的原因
于 2013-01-11T10:55:14.440 回答