你能不能告诉我哪里出错了,我的框架大小是wpf窗口的大小,代码是:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="BSP" Height="700" Width="990" WindowStartupLocation="CenterScreen">
<Grid Background="Green" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Frame Name="MainFrame" Source="LoginScreen.xaml" NavigationUIVisibility="Hidden" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>
</Window>
小于窗口的页面大小以及边距+宽度+标签大小的总大小小于页面大小但按钮显示为剪切。该页面的代码如下:
<Page x:Class="Loggedin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Height="660" Width="920"
Title="Loggedin">
<Grid Background="white" Margin="2">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" >
<Label Content="Loggedin as" Height="28" HorizontalAlignment="Left" Name="Loggedinas" />
<Button Content="LogOut" Margin="780,0,0,0" Height="28" Name="Logout" Width="50" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</Page>
你能帮助我吗,它是从2天开始吃掉我的大脑:(。以下是输出图片: 来自Visual Studios的图片:http://clip2net.com/s/1Fpb7
来自运行时的图片:http://clip2net.com/s/1FpbQ
答案 0 :(得分:1)
您是否考虑过使用DockPanel而不是StackPanel?它似乎更适合您想要实现的布局:
<DockPanel VerticalAlignment="Top">
<Label Content="Loggedin as" Height="28" HorizontalAlignment="Left" Name="Loggedinas" />
<Button Content="LogOut" Height="28" Name="Logout" Width="50" HorizontalAlignment="Right"/>
</DockPanel>
每当你的边距看起来像Margin="780,0,0,0"
时,通常意味着你的工作太辛苦了,而且有更好的方法。在我的快速划痕测试中,780像素的左边距正在按下框架上的按钮。