【发布时间】:2018-01-09 13:08:27
【问题描述】:
我正在自学 WPF,遇到了一个令我困惑的问题。在下面的 XAML 中,当我打开应用程序时,标签和图像位于窗口的左上角,但是当我最大化窗口时,它们会移向中间。我缺少什么会使控件保持其相对位置?
<Window x:Class="WafLuckyDog.Presentation.Views.ShellWindow"
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:vm="clr-namespace:WafLuckyDog.Applications.ViewModels"
mc:Ignorable="d" Title="{Binding Title}" Icon="{StaticResource ApplicationIcon}" Width="994.273" Height="840"
d:DataContext="{d:DesignInstance vm:ShellViewModel}">
<Window.Background>
<ImageBrush ImageSource="{StaticResource Background}"></ImageBrush>
</Window.Background>
<DockPanel Margin="0,0,-539,0">
<Grid>
<Image Name="Logo" HorizontalAlignment="Left" Margin="0,10,0,669" Width="129"
Source="{StaticResource Logo}" />
<Label Content="Label" HorizontalAlignment="Left" Margin="10,145,0,0" VerticalAlignment="Top" Foreground="AntiqueWhite"/>
</Grid>
</DockPanel>
</Window>
【问题讨论】:
-
Margin="0,10,0,669" 左边距为 669px。放大窗口时,您会更清楚地看到页边距
-
@DieterB 669 是底部边距,不是以像素为单位,而是以与设备无关的单位。
-
@DieterB 最后是下边距。左上右下