我被拖动了窗体上的控件,当我运行它并最大化窗口时,控件不会保留在我放置的相同位置。
当窗口最大化时如何将控件保持在同一位置?
这是XAML代码:
<Window x:Class="Wpf_App1.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:Wpf_App1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Background>
<ImageBrush/>
</Grid.Background>
<Grid HorizontalAlignment="Left" Height="319" VerticalAlignment="Top" Width="517">
<Image x:Name="image" HorizontalAlignment="Left" Height="319" VerticalAlignment="Top" Width="517" Stretch="Fill" Source="C:\Users\Moath\OneDrive\Documents\Visual Studio 2015\Projects\Wpf_App1\Wpf_App1\Images\LoginScr.jpg"/>
<Grid HorizontalAlignment="Left" Height="52" Margin="310,112,0,0" VerticalAlignment="Top" Width="122">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBox x:Name="textBox" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="16" Width="120
" Margin="0,10,0,0" >
<TextBox.Background>
<ImageBrush Stretch="None"/>
</TextBox.Background>
</TextBox>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Margin="0,10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="16
" Width="120
" >
<TextBox.Background>
<ImageBrush Stretch="None"/>
</TextBox.Background>
</TextBox>
</Grid>
</Grid>
</Grid>
</Window>
答案 0 :(得分:0)
Grid
内设置Margin="310,112,0,0"
编辑,这是导致问题的原因。 Margin
的工作方式与Margin="left,top,right,bottom"
类似,因此您将left Margin
设置为310,将top Margin
设置为112,这就是textbox
不在左上角的原因。尝试将Margin
设置为0。
所以看起来像这样:
<Grid HorizontalAlignment="Left" Height="52" Margin="0" VerticalAlignment="Top" Width="122">