为什么我看不到源代码和编译之间大小相等的WPF表单呢?我的意思是状态栏和按钮在图像之间看起来不一样。他们有不同的立场。编译前的第一个图像。之后的第二张图片。
我做错什么了?
很抱歉有个初学者的问题。


<Window x:Class="WebDownloader.MainWindow"
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"
xmlns:local="clr-namespace:WebDownloader"
mc:Ignorable="d"
Title="MainWindow" Initialized="Window_Initialized" Closed="Window_Closed" ResizeMode="NoResize" Height="190" Width="225.395">
<Grid>
<Button x:Name="MainButton" Content="Done" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="135,108,0,0" Click="MainButton_Click" FontFamily="Times New Roman"/>
<StatusBar HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,133,0,0" Width="209" Height="18" FontFamily="Times New Roman">
<StatusBarItem Content="StatusBarItem" Height="18" VerticalAlignment="Top" FontFamily="Times New Roman" Width="78" HorizontalAlignment="Left"/>
</StatusBar>
</Grid>
发布于 2017-08-22 10:24:10
问题是,您正在使用具有固定大小和边距的静态布局来放置项目。你真的不应该这样布局一个WPF应用程序。
使用相对布局,并按照应该使用的方式使用Grid:使用行和列。
我删除了布局不需要的所有属性,以尽可能缩短这个示例。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Content="Done"
Grid.Row="1"
HorizontalAlignment="Right"
Width="75"
Margin="0 0 5 5"/>
<StatusBar Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<StatusBarItem Content="StatusBarItem"
HorizontalAlignment="Left"/>
</StatusBar>
</Grid>

信息
您可以删除Height和Width属性的Window,并使用SizeToContent="WidthAndHeight"时,您希望您的UI是大的,因为它必须显示所有的内容。
发布于 2017-08-22 10:32:55
这个文章值得一看;它很好地概述了WPF窗口。
你可以控制窗口的height和width。
<Window Height="200" Width="300">
<!-- Content here -->
</Window>给你一个300宽200高的窗户。
此外,您还可以指定一个最小值和最大值-当您希望您的用户能够调整您的窗口大小时,这是非常有用的。
<Window Height="200" Width="300" MinWidth="200" MaxWidth="500">
<!-- Content here -->
</Window>为您提供一个200到500宽的窗口,默认宽度为300。
您可以指定如下的设计高度和宽度
<Window Height="200" Width="300" DesignWidth="500" DesignHeight="500">
<!-- Content here -->
</Window>上面写着“使我的窗户300宽200高,但使它在我的设计师500乘500”。
尽管如此,一个更好的方法通常是使用SizeToContent,以便您的窗口适合您的内容。像这样
<Window SizeToContent="WidthAndHeight">
<!-- Content here -->
</Window>https://stackoverflow.com/questions/45814789
复制相似问题