设计器视图和编译构建之间的不同位置

时间:2014-03-24 01:09:27

标签: c# wpf

在我第一次尝试使用WPF时,我遇到了一个问题,我在设计器的按钮视图中选择的坐标与我在编译程序时看到的不同。这是它的样子:

enter image description here

enter image description here

编译版本中的按钮略低(裁剪)。关于这里发生了什么的任何想法?

代码:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Player.MainWindow"
        Title="Player" ResizeMode="CanMinimize" StateChanged="Window_StateChanged" Icon="Resources/radio.ico" WindowStartupLocation="Manual" Closing="Window_Closing" Left="0" d:DesignWidth="448" d:DesignHeight="110" Width="448" Height="110">
    <Grid Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button x:Name="nextButton" Content="Next" HorizontalAlignment="Left" Margin="32,38,0,0" VerticalAlignment="Top" Width="45" Click="nextButton_Click" Height="22"/>
        <TextBox x:Name="prevButton" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="209" IsEnabled="False" TextAlignment="Center"/>

    </Grid>
</Window>

1 个答案:

答案 0 :(得分:2)

我打开GIMP并将你的图像放在彼此的顶部,顶部有50%的透明度,这就是结果:

enter image description here

瞧 - XAML设计师和编译后的输出相同。我甚至认为VS设计师会显示某种背景编译版本的XAML,以实现这种高保真度的表现。

返回您编辑过的问题:根据此问题:Why is a window larger in runtime?您需要在Grid上设置宽度/高度,并设置SizeToContent的{​​{1}}属性到Window

以下是您的代码的更新版本:

WidthAndHeight

结果是: enter image description here

相关问题