Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Grid is not stretching vertically

I've the following Grid in the main window:

<Grid Name="gridMain" Width="Auto" VerticalAlignment="Stretch" Height="Auto">
</Grid>

I'm adding a UserControl dynamically in the grid. The main window only has this grid. I want the grid to be stretched both horizontally and vertically and should fill up entire window. The grid is stretching horizontally but doesn't stretch vertically. Any idea why? What do I need to do to make the grid stretch vertically?

EDIT

Here is the complete XAML.

<Window x:Class="Sensitech.TurboValidator.UserControls.ConveyorBelt"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ConveyorBelt" Height="329" Width="714" xmlns:my="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">
    <Grid Name="gridMain" Width="Auto" VerticalAlignment="Stretch" Height="Auto" Background="Cyan">

    </Grid>
</Window>
like image 555
Donotalo Avatar asked Dec 27 '11 05:12

Donotalo


1 Answers

Try setting row height to *

<Grid Name="gridMain" >    
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
</Grid>

Similarly define ColumnDefinition and set Width to *

Also make sure grid is the one not stretching not the user control. You can easily do that by assigning some background color to Grid.

like image 94
Haris Hasan Avatar answered Nov 15 '22 19:11

Haris Hasan