Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my WPF window sizes defaulting to be huge

Tags:

I have a wpf application with a few forms. At design time they are small, and they are not set to auto size. However at run time they are giant, even with no content in them to make them big.

Why is this happening?

Here is one of the forms

<Window x:Class="SuperPluginPicker"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"               xmlns:tree="clr-namespace:Aga.Controls.Tree;assembly=Aga.Controls"               mc:Ignorable="d"               d:DesignHeight="296" d:DesignWidth="634" Title="Plugin Selector" WindowStartupLocation="CenterOwner">     <Grid>         <DockPanel LastChildFill="true">             <StackPanel DockPanel.Dock="Bottom" Height="30" Orientation="Horizontal">                 <Button Content="Ok" Name="btnOk" Click="btnOk_Click"></Button>                 <Button Content="Cancel" Name="btnCancel" Click="btnCancel_Click"></Button>              </StackPanel>             <StackPanel DockPanel.Dock="Right">                 <Label Content="Selected Plugins"></Label>             <ListBox Name="lstSelectedPlugins"  Width="200">                 <ListBox.ItemTemplate>                        <DataTemplate>                            <Label Content="{Binding Name}" />                      </DataTemplate>                  </ListBox.ItemTemplate>              </ListBox>             </StackPanel>             <StackPanel DockPanel.Dock="Right" Width="100" VerticalAlignment="Center">                 <Button Content="Add" Name ="btnAdd" Click="btnAdd_Click"></Button>                 <Button Content="Remove" Name="btnRemove" Click="btnRemove_Click"></Button>                 <Button Content="Remove All" Name="btnRemoveAll" Click="btnRemoveAll_Click"></Button>             </StackPanel>              <tree:TreeList  x:Name="pluginTree">                 <tree:TreeList.View>                     <GridView x:Name="treeGrid">                         <GridView.Columns>                              <GridViewColumn Width="Auto" Header="Name">                                 <GridViewColumn.CellTemplate>                                     <DataTemplate>                                         <StackPanel Orientation="Horizontal">                                             <tree:RowExpander/>                                              <TextBlock Text="{Binding Name}"></TextBlock>                                         </StackPanel>                                     </DataTemplate>                                 </GridViewColumn.CellTemplate>                             </GridViewColumn>                             <GridViewColumn Header="Author" Width="Auto"  DisplayMemberBinding="{Binding Author}"/>                             <GridViewColumn Header="Description" Width="Auto" DisplayMemberBinding="{Binding Type}"/>                           </GridView.Columns>                     </GridView>                 </tree:TreeList.View>             </tree:TreeList>         </DockPanel>     </Grid> </Window> 
like image 368
Jason Coyne Avatar asked Jun 30 '10 02:06

Jason Coyne


People also ask

Which type of sizing is used in WPF?

Fixed Proportional Sizing in WPF.

How do I open a WPF window in full screen?

Currently, the only way I know how to fullscreen my wpf application is: WindowStyle=None and WindowState=Maximized (and Topmost=True, though this is just needed to make sure it's above everything else).


1 Answers

If you create a <Window/> with this code:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" /> 

Then when you run that from Visual Studio it will display a window the same size as the one you put in your question. So this isn't anything you explicitly did.

What you've encountered is the default computed size of a WPF Window. For different results, specify a SizeToContent parameter on the Window, as paxdiablo pointed out, or explicitly set the size of your window with the MinHeight, MaxHeight, Height, MinWidth, MaxWidth, and/or Width properties.

like image 65
Rob Perkins Avatar answered Nov 03 '22 01:11

Rob Perkins