问题
Hi guys i am new to c# wpf.I have a problem that i want to include ScrollViewer
in my Groupbox
but it is not working my code is :
<GroupBox
Margin="10,10,0,0"
Grid.Row="0"
Grid.ColumnSpan="3"
Height="150"
>
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140"/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label
Margin="0,6,0,0"
Content="SSID"
Grid.Row="0"
>
</Label>
<TextBox
Margin="0,6,0,6"
Grid.Column="1">
</TextBox>
<Label
Margin="0,6,0,0"
Content="(1024)"
Grid.Column="2"
>
</Label>
<Label
Margin="0,6,0,0"
Content="Authentication Mode"
Grid.Column="0"
Grid.Row="1"
>
</Label>
<ComboBox
Margin="0,6,0,6"
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding ACAvailableSecurityTypes}"
SelectedItem="{Binding ACSelectedSecurityType}"
/>
<Label
Margin="0,6,0,0"
Grid.Row="2"
Grid.Column="0"
Content="VLAN"
/>
<TextBox
Margin="0,6,0,6"
Grid.Row="2"
Grid.Column="1"
/>
<Label Grid.Row="2"
Grid.Column="2"
Content="(1-4094)"/>
<Button
Grid.Row="3"
Grid.Column="2"
Content="Add SSID"
HorizontalAlignment="Left"
Width="70"
Style="{StaticResource AppButtons}"/>
</Grid>
</ScrollViewer>
</GroupBox>
Any help would be highly appreciable.Thanks
回答1:
In Order to See your Scroll bar, your scrollviewer should have lesser height than your groupbox, do like this, you can see the scrollbar, Set the height and VerticalScrollBarVisibility
<ScrollViewer Height="100" VerticalScrollBarVisibility="Auto">
<GroupBox
Margin="10,10,0,0"
Grid.Row="0"
Grid.ColumnSpan="3"
Height="150"
>
......
</GroupBox>
</ScrollViewer>
回答2:
Place the ScrollViewer
outside the GroupBox
, not inside:
<ScrollViewer>
<GroupBox Margin="10,10,0,0"
Grid.Row="0"
Grid.ColumnSpan="3"
Height="150" >
...
...
</GroupBox>
</ScrollViewer>
来源:https://stackoverflow.com/questions/23932043/scrollviewer-is-not-working-inside-groupbox