2012-03-05 56 views
0

能否請你告訴我在哪裏出了問題,我的幀大小採用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天吃了我的大腦:(以下是輸出的圖片: 產品圖從視覺工作室:http://clip2net.com/s/1Fpb7

從產品圖運行時間:http://clip2net.com/s/1FpbQ

回答

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像素的左邊距將按鈕從框架上推下。

+0

這幫助了一個小修改也需要使其正常工作,即設置幀的水平和垂直對齊來拉伸。謝謝你的答案。 – surpavan 2012-03-06 08:08:30