SWF to XAML
LINQ with joins

Resizing the Main Window of WPF Applications

If the main Window of an WPF application should automatically be sized to its content, setting the Width and Height properties to Auto does not help. With this setting the Window gets a default height and width. To resize the main window to its content, the property SizeToContent can be set. If the Height and Width properties are set as well to Auto, the Window gets resized dynamically as the size of the content changes.

<Window x:Class="SizingTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Width="Auto" Height="Auto" SizeToContent="WidthAndHeight" >
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Label Margin="5" Grid.Column="0" Grid.Row="0">Value 1:</Label>
    <Label Margin="5" Grid.Column="0" Grid.Row="1">Value 2:</Label>
    <Label Margin="5" Grid.Column="0" Grid.Row="2">Value 3:</Label>
    <TextBox Margin="5" Grid.Column="1" Grid.Row="0" MinWidth="100" />
    <TextBox Margin="5" Grid.Column="1" Grid.Row="1" MinWidth="100" />
    <TextBox Margin="5" Grid.Column="1" Grid.Row="2" MinWidth="100" />
  </Grid>
</Window>

Christian

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Brother

Thanks for the valuable information

Dragoljub

I didn't know this. It solved my problem! Thanks!

sty21um

thanks, it helped

Gregg

That's fine, but if you don't want the USER to resize the window, add: ResizeMode=NoResize to the window properties, i.e. Window ... ResizeMode=NoResize ... /Window

subha basu

thnx, christian. It works for me, also.

jordan shoes

A great boost emotional strength, therefore, it is an important precondition of all ethical behavior, who had no strong ambition, also won't be able to put this warm in career aspirations.

wow account

In my WPF application, i have many Components like Grids, StackPanels and inside them other components.
What I want to do is to autoresize all these components according to how the user resizes the window of the Application. I want user to see all components, no matter how small they will become...
I have put them all in a ViewBox, but when I maximize my application I see left and right white spaces.

What are the steps to do application's components auto-resized and auto-adjusted to the window???
I should change the size of ALL components dynamically? (I hope not...)

coach outlet stores

sounds awesome! and this post is just gorgeous!*

Supra Shoes

At Christmas and always, may peace and love fill your heart, beauty fill your world, and contentment and joy fill your days.

moncler jackets

i love you post

moncler jackets

i love you post

beat making software


Very nicely written post it contains useful information for me. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.

air max 90

oh so funny!

coach outlet

nothing is impossible for a willing heart.

air max 90

Tomorrow is an other day!@

christian louboutin

*I hope my family and all friends are happy everyday.

Link building

hello..This is a great web site. Good polished UI and nice informative articles. I will be coming back in a bit, thanks for the great article.

FJODOROVIvan19

Дизайн, ремонт квартир киев офисов

coach outlet online

Do something to have faith, believe in yourself

Newxe

It's a Very helpful article for me. Actually, I am fond of reading online punjabi news. Thanks for writing such a complete ..And,I wantn't to miss them.
Thank you for sharing..

thomas sabo

Finally found what I want, I'm a beginner content inside of great help to me with you, share

Cars Ghana

I like your post & I will always be coming frequently to read more of your post. Thank you very much for your post once more.

Dubai car rentals

Nice info you have here. I hope this will help a lot of people. Keep up the good work...We hope you will visit our blog often as we discuss topics of interest to you.

Thomas Sabo Australia

I became interested in the topic and I am thinking whether I could use your texts on my paper, of course with the quotation. Please contact with me, thanks very much.

Thomas Sabo Australia

I became interested in the topic and I am thinking whether I could use your texts on my paper, of course with the quotation. Please contact with me, thanks very much.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)