0
votes

I'm trying to create a login page for a Windows 8 application. I want it to look like the Windows 8 version of OneDrive, so I'm attempting to center the content in a ScrollViewer. However, the control appears to be unable to center it's content when you use the 'MaxWidth' property. Here's an example of the problem.

<Page x:Class="App1.MainPage"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  mc:Ignorable="d"
  xmlns:local="using:App1"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <ScrollViewer Grid.Row="1">
        <StackPanel MaxWidth="900" Background="Red"/>
    </ScrollViewer>
</Grid>

If you run this, the red panel will appear off to the right in la-la land. If you replace the ScrollViewer with a Grid, you'll see how the content is supposed to be laid-out. Anyone have an idea how to work around this problem?

1

1 Answers

0
votes

Workaround : You can surround your StackPanel with a Border and it will be centered like it should. Keep the MaxWidth on the StackPanel.