繁体   English   中英

C#WPF调试后与IDE的大小不同吗?

[英]C# WPF different size from IDE after debugging?

http://i.stack.imgur.com/2gOLN.png

我在Blend/VS2012 IDEDebugging出现外观不同的问题。 IDERectangle位于中心,但是在编译或调试时,边距的大小不同。 在我看来,这是因为窗口边框的大小不同。 我真的很想解决这个问题。 有什么建议么?

谢谢。

XAML

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="202" Width="194">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
    <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="151" Margin="10,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="166"/>
</Grid>

编辑的XAML代码:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="202" Width="194">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
    <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="151" Margin="10" Stroke="Black" VerticalAlignment="Center" Width="166"/>
</Grid>

结果是一样的。 这是我的电脑的问题吗?

您的问题是窗口大小包括Chrome大小(窗口边框和关闭/最大最小按钮之类的东西)。

因此,您的网格就是您所请求的大小,但它不适合您所请求的窗口大小。

我可以解决您的问题,以使输出窗口看起来像这样,窗口大小为:

宽度:202高度:210

在Windows 8上

但是,您应该将窗口大小设置为SizeToContent="WidthAndHeight"

例:

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication4"
        x:Name="window"
        Title="MainWindow"
        SizeToContent="WidthAndHeight">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
    <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="151" Margin="10,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="166"/>
</Grid>
</Window>

因此,您不能假设Chrome的大小可能与Windows的不同版本不同。

您还应该获得Snoop 它可以帮助您非常轻松地调试此类问题,使用Shift + Ctrl将鼠标悬停在控件上时会在控件上显示一个红色边框,因此您实际上可以看到Grid超出了可见窗口,同时显示了UI的实际元素布局

图片

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM