ServicesResourcesConferencesOur TeamWeblogsAboutContact
   

Subscriptions

Post Categories

News

My new books

My Blogroll

INETA UG Leaders

Affiliations

News

Archives

Christian Nagel's OneNotes

.NET Training, Consulting, Coaching & Development


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

posted on Tuesday, January 01, 2008 9:05 PM

# Anothr feed track -thinktecture blogs @ Thursday, January 10, 2008 6:53 AM

One new subscriber from Anothr Alerts
anothr user


Powered by Community Server, by Telligent Systems