Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Designer中使用的窗口边距在运行的程序中变小了?_C#_Wpf_Xaml_Margin_Designer - Fatal编程技术网

C# 为什么Designer中使用的窗口边距在运行的程序中变小了?

C# 为什么Designer中使用的窗口边距在运行的程序中变小了?,c#,wpf,xaml,margin,designer,C#,Wpf,Xaml,Margin,Designer,在Windows 8.1上使用Visual Studio 2013中的设计器,并创建一个简单窗口,其中文本框的右边和底部都有10p的边距,当我运行该程序时,边距就会发生变化。 我该如何避免这种情况 示例图片:(我还不能发布图片,所以这里是裸链接) 另一幅图片更能说明这一点 如上图所示,运行程序时,边距会发生显著变化 我的Windows XAML代码是: <Window x:Class="Test.MainWindow" xmlns="http://schemas.microso

在Windows 8.1上使用Visual Studio 2013中的设计器,并创建一个简单窗口,其中文本框的右边和底部都有10p的边距,当我运行该程序时,边距就会发生变化。 我该如何避免这种情况

示例图片:(我还不能发布图片,所以这里是裸链接)

另一幅图片更能说明这一点

如上图所示,运行程序时,边距会发生显著变化

我的Windows XAML代码是:

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="400" Width="800" Focusable="False" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" UseLayoutRounding="False">
<Grid>
    <TextBox HorizontalAlignment="Left" Height="351" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="774"/>
</Grid>

另一个图像的XAML代码:

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="400" Width="800" Focusable="False" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" UseLayoutRounding="False">
<Grid>
    <TextBox HorizontalAlignment="Left" Height="205" Margin="10,156,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="774"/>
    <Button Content="Button" HorizontalAlignment="Left" Margin="709,55,0,0" VerticalAlignment="Top" Width="75"/>
    <RadioButton Content="RadioButton" HorizontalAlignment="Left" Margin="699,101,0,0" VerticalAlignment="Top"/>
</Grid>


只需指定边距并允许其拉伸,而不是指定宽度和高度:

<TextBox HorizontalAlignment="Stretch" Margin="10" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Stretch" />

我添加了XAMLCode。我不想要一个实际的拉伸文本框,这只是为了解释问题,我的问题是,我经常按右下角的“捕捉点”对齐项目,其中一些项目只有固定大小,需要它们。@user2001803固定大小有问题。最好使用相对大小和布局来控制它……相对于用户的设备。事实上,它被认为是一种最好的做法,可以避免使用固定的位置来支持wpf的亲戚,正如微软在这里所说:@user2001803首先你需要阅读如何设计布局!这与我的边距消失和减少控件宽度有什么关系?我的窗口从不改变大小,分辨率总是比窗口大,所以我不需要相对大小。
<Grid>
   <Grid.RowDefinitions>
       <RowDefinition Height="*" />
       <RowDefinition Height="*" />
       <RowDefinition Height="2*" />
   <Grid.RowDefinitions>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />
       <ColumnDefinition Width="Auto" />
   <Grid.ColumnDefinitions>

  <TextBox Grid.Row="2" Grid.ColumnSpan="2" Margin="10" TextWrapping="Wrap" Text="TextBox" />
  <Button Grid.Row="0" Grid.Column="1" Content="Button" Margin="10" Width="75"/>
  <RadioButton Grid.Row="1" Grid.Column="1" Content="RadioButton" Margin="10" />

</Grid>