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.
Edit: Also, the layout is Canvas
.
Classic theme:
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>
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.
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.
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?
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.
精彩评论