Reputation: 1116
This issue occurs in a WPF application.
The project is using a ContentControl that loads a Canvas and draws in this canvas whatever needs to be drawn. This canvas has vertical and horizontal scrollbars.
Now I need to wrap this ContentControl into a grid, next to a GroupBox.
So I replaced:
<ContentControl Grid.Row="1" Content="{Binding Viewer.Content}" Margin="10,10,0,0"/>
with:
<Grid Grid.Row="1" x:Name="Load_Grid" Panel.ZIndex="2" Background="DarkGray" Opacity="0.9">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<GroupBox Grid.Column="0"
x:Name="Legend_Inserts_Status"
Header="Legend"
HorizontalAlignment="Left"
BorderBrush="#FF4EA8DE"
FontSize="10"
Foreground="#FF436EFF"
Width="80"
Visibility="{Binding DisplayLegend,Converter={StaticResource BoolToVis}}">
<Grid>
<!--My groupbox content here -->
</Grid>
</GroupBox>
<ContentControl Grid.Column="1" Content="{Binding Viewer.Content}" Margin="10,10,0,0"/>
</Grid>
When doing this, my new GroupBox renders properly, the canvas is still displayed but without its horizontal and vertical scrollbars. Is there any reason why?
Actually, even if I comment the GroupBox, the scroll bars are removed. So it seems that removing the scroll bars comes from wrapping the ContentControl into the grid.
Upvotes: 1
Views: 67
Reputation: 23280
This is occurring because you have your Column's set to an Auto
Width
which by definition allows the children of that column to consume whatever space required and size to the columns content.
By doing so you're negating any boundary to invoke the ScrollViewer
built into the ContentControl
template. Basically because it has nothing telling it "Hey! You're only allowed to be x,y size and if you go over that size then we need scrollbars." is a plain way of putting it. So you're going to need to set a MaxWidth
or use a *
or something that will invoke that boundary for the ScrollViewer
to kick in.
Upvotes: 1