Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have taken 4 column and 5 Row in my WPF application.but when i am maximize the size of Main Window,the space between Rows is also increase.So how to make page responsive in WPF Application(xaml)so that there is less space in rows and UI Look good.

Expecting a positive reply.
Thanks in advance.

What I have tried:

I had reduces the height space between the rows.but still facing the problem.
Posted
Updated 12-Dec-17 17:16pm

Begin to use containers like "DockPanel" and "WrapPanel - and combine them with different "vertical-horizontal" orientation, they has auto arrange etc. In WPF previous Winform experience almost useless...
Think different! :-)
 
Share this answer
 
Comments
Member 13569324 12-Dec-17 5:08am    
I am already using grid panel in application.
________________ 12-Dec-17 5:22am    
Good, but StackPanel will arrange the inner controls automatically. I agree, the design will be completely different, but it will solve the problem with margins and anchors fine tuning....
First I've got to harp on the terminology... You're using responsive in a web sense and additionally the behavior you're describing fits that definition of responsive.

When talking in the WPF realm, responsive is primarily used to describe threading and responding to user's actions.

The default sizing in WPF grids is relative, meaning that it's assigned a value relative to the grid height and it's weighted value. By default a RowDefinition gets a weighted value of 1. As such, if you have 5 rows and you leave them to their defaults each row gets 1/(1+1+1+1+1) = 1/5 of the total height.

Now let's say you change some of those relative values, and you assign the last row to have a value of 2. That means the total weighting of the grid height is now 6, and rows 1 - 4 will get 1/(1+1+1+1+2)=1/6 of the height and row 5 will get 2/6.

The RowDefinition can also take a height of "Auto" which will auto size the height based on the content. From your description, that's probably what you're going to want.

It also has a MinHeight and MaxHeight property if you just want to avoid it getting over or under a particular value.

Auto and relative heights can be combined. A very common example of height assignments is something like:
<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="*"/>
</Grid.RowDefinitions>

Which means make rows 1 - 4 auto and the last row fill up the rest of the available space.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900