Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a window larger in runtime?

Tags:

c#

dimensions

wpf

I have a window set to 340 x 146 px, not resizable.

In designer the window size is correct. But when I run the application it is bigger. enter image description here

Edit: Also, the layout is Canvas.

Classic theme:

enter image description here

Edit2:

After running snoop (thanks Zach), it appears that actual dimensions are what I specified. But the client area is bigger than one in visual studio.

I understand now that the client size stretches, when windows size is fixed to certain dimensions. However I think this makes Canvas layout in window unusable.

Edit3:

<Window x:Class="TI.Presentation.Views.AutentizationWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Authentication" Height="146" Width="340" ResizeMode="NoResize" Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}" >
    <Canvas>
        <Label Canvas.Left="12" Canvas.Top="12" FontSize="15" Width="217">Enter authentication code here:</Label>
        <TextBox Canvas.Left="12" Canvas.Top="38" Height="23" Name="code" Width="294" FontSize="14" />
        <Button Canvas.Top="67" Content="OK" Height="28" Width="100" Canvas.Left="206" FontSize="14" IsDefault="True" Click="OKClick" />
    </Canvas>
</Window>
like image 797
Kugel Avatar asked Jan 28 '11 18:01

Kugel


3 Answers

I'm going to answer this myself after poking around.

The window's ActualWith and ActualHeight are equal to Width and Height set in the designer.

What changes, is the client area. The dimensions of client are will be window dimensions minus theme border. This, however, breaks Canvas design because its absolutely positioned and canvas dimensions changed based on theme.

The way to make Canvas design work. Is to set dimensions on Canvas, remove dimensions on window and set SizeToContent on window accordingly. This way, cavnas dimensions stay fixed and Window size changes based on how think the theme border is.

like image 59
Kugel Avatar answered Nov 16 '22 00:11

Kugel


Simply because the size u specify dosent take into account the border which will be taken from the Operating System's current Theme... If you are setting 200x200 you are getting that full space.. you wouldn't want it to be reduced to 190x190 box because of 5px border either side. and that too will change to the Current Theme on the Operating System, like Aero, Classic, etc.

like image 44
Shekhar_Pro Avatar answered Nov 16 '22 02:11

Shekhar_Pro


Does the window have a DesignHeight and DesignWidth set? See WPF UserControl Design Time Size.

Edit: My next thought would be to try using Snoop to see at runtime what exactly is different. Is it the size, the padding, the margin, or something else?

like image 37
Zach Johnson Avatar answered Nov 16 '22 01:11

Zach Johnson