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>
4
  • Is the size changing on the same machine, or between machines?
    – Ben Voigt
    Jan 28, 2011 at 18:16
  • i suspect it has somthing to do with margins... see what happens if you set the parent container's margin to 0 all the way Jan 28, 2011 at 18:26
  • I have no margins set anywhere.
    – Kugel
    Jan 28, 2011 at 18:30
  • Could you paste the XAML code ?
    – Matthieu
    Jan 28, 2011 at 18:44

4 Answers 4

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.

1
  • SizeToContent solution solved the problem for me, thank you!
    – Funbit
    Mar 24, 2016 at 9:00
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.

3
  • 3
    But I think he's talking about the padding in the window, especially on the right side.
    – kprobst
    Jan 28, 2011 at 18:14
  • 1
    this is wrong answer noticed how insides of the window got bigger?
    – Kugel
    Jan 28, 2011 at 18:19
  • it's exactly opposite when you set window to 200x200 windows stays that way. but client are changes.
    – Kugel
    Jan 28, 2011 at 18:47
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?

2
  • @Kugel: Hmmm...ok. I've edited my answer with another suggestion. Jan 28, 2011 at 18:33
  • Just before I read you comment I started Snoop installation. :-)
    – Kugel
    Jan 28, 2011 at 18:36
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.