user101010101
user101010101

Reputation: 1659

DataGrid Sizing Issue

I am trying to load data into a datagrid but I am having a nightmare with sizes. My datagrid seem to take as much space as it wants. I want it to load into the current size and display scroll bars if needed.

Could someone explain how the sizing works thank you.

Example:

<Grid Name="MainUI" Height="Auto" Width="Auto">
    <Grid.RowDefinitions>
       <RowDefinition Height="Auto"></RowDefinition>
       <RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<Grid Name="MainGrid" Grid.Row="1" VerticalAlignment="Top" Height="Auto" Width="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>

   <TabControl TabStripPlacement="Bottom" Name="Main_Tab" VerticalAlignment="Top" Visibility="Visible" />
 </Grid>

</Grid>

Within the tab control I create a datagrid on a new tab item in the code behind when this happens, the datagrid takes as much room as possible.

The datagrid of itemTab has no sizing on it when I load it.

Thanks

Upvotes: 2

Views: 133

Answers (1)

Rachel
Rachel

Reputation: 132618

Setting the Height/Width to Auto means the control should take up as much space as it needs. This means if the control needs more space than is available in the UI, it's allowed to stretch the parent control and take up however much space it wants.

Remove the Height="Auto" and Width="Auto" to fix the issue

If it is still giving you trouble, try setting HorizontalAlignment and VerticalAlignment to Stretch. This will make the control will grow or shrink itself to take up all space available to it, however it won't expand the container it is in to take up additional space.

Upvotes: 3

Related Questions