2
votes

Here is my XAML for a UWP Page.

<Page
x:Class="App.AddComment"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" HorizontalContentAlignment="Stretch"  HorizontalAlignment="Stretch"
>
<Page.BottomAppBar>
    <CommandBar>
        <CommandBar.Content>
            <Grid/>
        </CommandBar.Content>
        <AppBarButton Icon="PostUpdate" Label="Post"/>
    </CommandBar>
</Page.BottomAppBar>

<StackPanel Margin="5,10,5,50" BorderBrush="Black" BorderThickness="3" Background="White" HorizontalAlignment="Stretch">
    <TextBlock Name="Title" HorizontalAlignment="Stretch" Margin="10" MinHeight="50" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Foreground="{StaticResource SystemControlBackgroundAccentBrush}" FontWeight="Normal" FontSize="20"/>
    <TextBox Name="CommentBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,20,10,20" AcceptsReturn="True" TextWrapping="Wrap" FontWeight="Thin" FontSize="18" VerticalContentAlignment="Stretch" Height="200" Header="Comment" PlaceholderText="Enter your comment here.."/>
</StackPanel>

But the StackPanel doesn't occupy the whole page(width).. Even though I set the HorizontalContentAlignment and HorizantalAlignment as Strech, it's not working.. I even tried grid in place of StackPanel but the issue still persists. Please see the image

1
Get rid of the margin. That is what is causing the problemAbsoluteSith

1 Answers

1
votes

It appears your StackPanel which is wrapping the page content has a Margin on it.

A Margin causes the control to add a gap to the outside of the control making it have that pushed in look like this:

Margin/Current look

What you might want to do is remove the margin if it's not required, or change it to a Padding.

<StackPanel Padding="5,10,5,50" BorderBrush="Black" BorderThickness="3" Background="White" HorizontalAlignment="Stretch">
    <TextBlock Name="Title" HorizontalAlignment="Stretch" Margin="10" MinHeight="50" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Foreground="{StaticResource SystemControlBackgroundAccentBrush}" FontWeight="Normal" FontSize="20"/>
    <TextBox Name="CommentBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,20,10,20" AcceptsReturn="True" TextWrapping="Wrap" FontWeight="Thin" FontSize="18" VerticalContentAlignment="Stretch" Height="200" Header="Comment" PlaceholderText="Enter your comment here.."/>
</StackPanel>

A padding causes the gap to appear inside of the control like this:

Padding look

This gives you the same layout of the content inside, but will have the edge-to-edge look you're wanting for the StackPanel/Grid.