Search code examples
c#wpfgrid-layout

Can you make grid column/rows change dynamically with window size?


I'm supposed to make an app to design a restaurant, so like dragging and dropping tables from a toolbox and whatnot. I was thinking of dragging them onto a grid, but I need the rows and columns to adapt to the window size. Is there any way to do this or should I change the control I'm using?


Solution

  • I am not sure what kind of control you are using. It would be better if you could elaborate more. Assume you are using WPF grid. Then you could use: * to indicate to fill the remaining space. So if the window size becomes bigger the grid column will become larger.

    Or use "auto" to automatically change grid row width and height based on its content. If you drag a table to the grid, the content of the grid is larger, so the "Auto" size would make grid bigger.

    <Grid.RowDefinitions>
            <RowDefinition Height="auto" Width="Auto" />
            <RowDefinition Height="*" Width="*"/>
    </Grid.RowDefinitions>