0
votes

I have a grid, with 3 rows. Row 2 has a variable height, the window is resizable, and I have a datagrid on Row 3, held within a scrollviewer, within a tabcontrol.

When there are many items in the scrollviewer, the scrollviewer expands until it reaches the "max height" available to it, however that max height is infinity... so it keeps growing and growing. What I want it to do, is stop expanding if that would mean it is pushing the parent grid out of bounds, and instead use its scroll functionality... Here is the general layout of it:

<TabControl Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3">
    <TabItem Header="Weapons">
        <ScrollViewer>
            <DataGrid>
                ...
            </DataGrid>
         </ScrollViewer>
     </TabItem>
</TabControl>

That is held within a grid which has 3 rows and 3 columns. There is content in rows 0 and 1 which I didnt put here, and obviously I took out the unnecessary info from Datagrid etc...

Example of what I see:

This is what it turns out like

As requested, the whole XAML. Not exactly short, which is why I thought the simplified version above would be better. XAML - Too large to fit in post

OK, so its there. I am looking at both datagrids held in different tabs of the tabcontrol on Row 2 of the grid.

Condensed "full" xaml:

<Grid>
<Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition />
    <ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
    <RowDefinition />
</Grid.RowDefinitions>

<Grid Grid.Row="0" Grid.Column="1">

    <Image Source="{StaticResource EmptySlot}" Margin="0" Width="34"/>
    <Image Source="{Binding AuraSlot, FallbackValue={StaticResource AuraSlot}}" Margin="0" Width="34"/>
</Grid>

<Popup AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=MainWindowName}" IsOpen="{Binding WeaponTooltipOpen}" HorizontalOffset="{Binding WeaponOffsetX}" VerticalOffset="{Binding WeaponOffsetY}" PopupAnimation="Fade" OpacityMask="White" >
    ...
</Popup>

<Grid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3">

    <Expander orizontalAlignment="Center">
        <Expander.Header>
            <TextBlock Text="Equipment Slots" HorizontalAlignment="Center" />
        </Expander.Header>

        <Grid Grid.Row="0" Grid.Column="1">
            ...
        </Grid>

    </Expander>
</Grid>

<TabControl Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3">
    <TabItem Header="Weapons">
        <Grid>
            <ScrollViewer CanContentScroll="True" >
                <DataGrid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding GroupedWeapons}" AutoGenerateColumns="False" IsReadOnly="True" AlternatingRowBackground="Gainsboro" AlternationCount="2" RowHeaderWidth="0">
                    <DataGrid.GroupStyle>
                        <GroupStyle>
                            ...
                        </GroupStyle>
                    </DataGrid.GroupStyle>

                    <DataGrid.Columns>
                        ...
                    </DataGrid.Columns>

                    <DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <StackPanel>
                                ...
                            </StackPanel>
                        </DataTemplate>
                    </DataGrid.RowDetailsTemplate>

                </DataGrid>
            </ScrollViewer>
        </Grid>
    </TabItem>


</TabControl>
</Grid>
1
What, pray tell, do css and wpf have to do with each other? And I think you can dump your datagrid directly in the tabitem and do away with the scrollviewer. The datagrid has a built-in scrollviewer which will work as expected. Also, css? Yeah, I'm back on that again.user1228
Sorry - I clicked it from the recommended tags, reading it as C# in my head not CSS. The daragrid doesnt scroll itself, as can be seen in screenshot. :(pingu2k4
WPF DataGrids most certainly do. You might be doing something else weird...user1228
That DataGrid does not scroll itself because you have it in a scroll viewer. Are you going to try suggestions? And post the grid columns and row definitions.paparazzo
I toggled on the setting to have the scroll for Datagrid, but it does the exact same thing as the containing scrollviewer. It reaches the bottom of the window but keeps adding content past that point.pingu2k4

1 Answers

0
votes

OK, eventually found the problem.

I don't really knwo the reason as to WHY this was the problem, because it doesn't really make sense to me, but WAY up in the code I had things wrapped in a stackpanel. The only 2 things stacked there were a textblock, and a Grid, with the grid containing a ton of other things, including all the code posted along with the question. Taking out that stackpanel made it work correctly, so I have now permanently replaced the stackpanel with another grid, using 2 differnet rows. :)