Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

How to know why my WPF Window is so big?

I have the following Window created in WPF. This is how it's shown:

enter image description here

I have no idea why the screen is shown so big and I don't know how to debug why is it getting so wide.

This is the code related to the problem:

<Window x:Class="Picis.CpCustomize.CustomizeControls.Dialogs.EditIntegerWindow"
MinWidth="350"
SizeToContent="Height"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ResizeMode="CanResize" 
ShowInTaskbar="False" 
WindowStartupLocation="CenterScreen" 
WindowState="Normal"
Loaded="OnWindowLoaded">

<!-- Main frame -->
<Grid>

    <!-- Layout -->
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <TextBlock VerticalAlignment="Center" MinWidth="100" TextAlignment="Right">
        <TextBlock.Text>
            <Binding Converter="{StaticResource Localizer}" ConverterParameter="General.Value" />
        </TextBlock.Text>
    </TextBlock>

    <TextBox x:Name="valueTextBox" Grid.Column="1" Margin="5" Text="{Binding Path=Value}"/>

    <TextBlock  VerticalAlignment="Center"  Grid.Row="1" Grid.Column="0"  HorizontalAlignment="Right" Visibility="{Binding Path=ShowComments, Converter={StaticResource VisiConv}, ConverterParameter=Collapse}" MinWidth="100" TextAlignment="Right">
            <TextBlock.Text>
                <Binding Converter="{StaticResource Localizer}" ConverterParameter="EditParamDlg.Comment" />
            </TextBlock.Text>
    </TextBlock>

    <TextBox x:Name="commentTextBox" Grid.Row="1" Grid.Column="1" Margin="5" Visibility="{Binding Path=ShowComments, Converter={StaticResource VisiConv}, ConverterParameter=Collapse}" Text="{Binding Path=Comment}"/>

    <CheckBox Grid.Row="2" Grid.Column="1" Margin="5" x:Name="isDeletedCheckBox" Visibility="{Binding Path=ShowIsDeleted, Converter={StaticResource VisiConv}, ConverterParameter=Collapse}"
            IsChecked="{Binding Path=IsDeleted}">
        <CheckBox.Content>
            <Binding Converter="{StaticResource Localizer}" ConverterParameter="EditParamDlg.IsDeleted" />
        </CheckBox.Content>
    </CheckBox>

    <UniformGrid Grid.Row="3" Grid.Column="1" Margin="5" HorizontalAlignment="Right" Columns="2">
        <Button  x:Name="okButton" Click="OnOk"  IsDefault="True">
            <Button.Content>
                <Binding Converter="{StaticResource Localizer}" ConverterParameter="General.Ok" />
            </Button.Content>
        </Button>
        <Button x:Name="cancelButton"  Click="OnCancel" Margin="5,0,0,0"  IsCancel="True">
            <Button.Content>
                <Binding Converter="{StaticResource Localizer}" ConverterParameter="General.Cancel" />
            </Button.Content>
        </Button>
    </UniformGrid>

</Grid>
</Window>

My first question is how to debug this issue, the second one is what is happening in this specific scenario.

Thanks in advance.

Upvotes: 1

Views: 1120

Answers (6)

Scott
Scott

Reputation: 12050

This question is a duplicate of: Why are my WPF window sizes defaulting to be huge

And according to: Window Size when SizeToContent is not specified the default size when not specified is 60% of the width and 60% of the height of your primary screen.

Upvotes: 3

brunnerh
brunnerh

Reputation: 184486

The alignments on a window should not really do anything as there is no container to reference, but you only tell the window to contract to the content in height, i would change that behavior to both dimensions:

SizeToContent="WidthAndHeight"

How to debug this sort of thing? Maybe train your brain to be able to parse XAML and do layout on the fly... i know, not very helpful.

Upvotes: 1

Tigran
Tigran

Reputation: 62246

To me it seems this one:

HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"

It stratches the window...

Upvotes: 1

Alleo
Alleo

Reputation: 8528

<Window HorizontalAlignment="Stretch"

that is the problem, I guess.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564413

You explicitly set the window to stretch in width:

SizeToContent="Height"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"

This says, "make the window as wide and tall as possible, but then resize to the content of the height"

If you remove that, and set Width and Height to "Auto" (or leave out), you'll likely get what you want. Try just removing all three of those lines (which will leave out alignment, can cause default Width/Height of "Auto" to be used.)

Upvotes: 2

paparazzo
paparazzo

Reputation: 45096

Maybe this is filling existing space (like it is supposed to).

    <ColumnDefinition Width="*"/>

Upvotes: 0

Related Questions