surpavan
surpavan

Reputation: 1412

Frame Page controls layout

Could you please tell me where I have gone wrong, my frame size takes the size of the wpf window, code is:

<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>

The page size less than the window and also the total size of margin+width+size of label is less than the size of page yet the button is being displayed as cut. Code for the page is below:

<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>

Could you please assist me, it is eating my brain from 2 days :(. Following are pics of output: Pic from Visual Studios: http://clip2net.com/s/1Fpb7

Pic from Runtime: http://clip2net.com/s/1FpbQ

Upvotes: 0

Views: 1171

Answers (1)

ianschol
ianschol

Reputation: 686

Have you thought about using a DockPanel instead of a StackPanel? It seems to be a closer fit for the layout you're trying to achieve :

    <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>

Any time you have margins that look like Margin="780,0,0,0" it usually means you're working too hard and there's a better way to do it. In my quick scratch tests, the 780 pixel left margin was pushing the button off the frame.

Upvotes: 1

Related Questions