Why is a window larger in runtime?
Asked Answered
S

4

13

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>
Speakeasy answered 28/1, 2011 at 18:10 Comment(4)
Is the size changing on the same machine, or between machines?Moniliform
i suspect it has somthing to do with margins... see what happens if you set the parent container's margin to 0 all the wayBusch
I have no margins set anywhere.Speakeasy
Could you paste the XAML code ?Bixler
S
8

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.

Speakeasy answered 28/1, 2011 at 19:2 Comment(1)
SizeToContent solution solved the problem for me, thank you!Kigali
B
1

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.

Busch answered 28/1, 2011 at 18:12 Comment(3)
But I think he's talking about the padding in the window, especially on the right side.Abbieabbot
this is wrong answer noticed how insides of the window got bigger?Speakeasy
it's exactly opposite when you set window to 200x200 windows stays that way. but client are changes.Speakeasy
H
1

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?

Haematocryal answered 28/1, 2011 at 18:14 Comment(2)
@Kugel: Hmmm...ok. I've edited my answer with another suggestion.Haematocryal
Just before I read you comment I started Snoop installation. :-)Speakeasy
D
0

I'm probably stating the obvious, but it appears that the Windows theme is the difference. How do they compare if you switch to Windows classic theme.

Devious answered 28/1, 2011 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.