垂直对齐不起作用 XAML
Vertical Alignment doesn't work XAML
如何使用 XAML/C# 将 Windows 应用商店应用置于屏幕中央,包括其所有内容?
我试过这个:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
但是 vertical alignment
似乎不起作用,网格停留在屏幕顶部。
编辑: 我希望红色部分位于屏幕中央:
<Grid RequestedTheme="Light" Loaded="Grid_Loaded" Background="{ThemeResource AppBarItemBackgroundThemeBrush}">
<Grid.Resources>
<Storyboard x:Name="FadeImageStoryboard">
<DoubleAnimation From="0"
To="1"
Duration="0:0:0.7"
Storyboard.TargetName="BackgroundImage"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</Grid.Resources>
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Image Source="assets/113h.jpg" Stretch="Fill" x:Name="BackgroundImage" RequestedTheme="Light" Margin="0,-10,0,10" />
<Button x:Name="backButton" Style="{StaticResource NavigationBackButtonNormalStyle}"
Margin="23,45,0,0"
VerticalAlignment="Top"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" Click="backButton_Click"/>
<StackPanel x:Name="Container">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Margin="363,172,368,308" PlaceholderText="Last Name" BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="LastName"/>
<Button Content="Sign-Up" HorizontalAlignment="Left" Margin="360,417,0,0" VerticalAlignment="Top" Width="257" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
</Grid>
</StackPanel>
</Grid>
您的 Grid
包裹在 StackPanel
中。这意味着它在堆栈面板 中居中 。考虑到 StackPanel
的工作原理,这并没有多大意义。
取出 Grid
(使其成为根 Grid
的子项),居中将按您预期的方式工作。
<Grid RequestedTheme="Light" Loaded="Grid_Loaded" Background="{ThemeResource AppBarItemBackgroundThemeBrush}">
...
//No StackPanel!
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Margin="363,172,368,308" PlaceholderText="Last Name" BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="LastName"/>
<Button Content="Sign-Up" HorizontalAlignment="Left" Margin="360,417,0,0" VerticalAlignment="Top" Width="257" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
</Grid>
....
</Grid>
如何使用 XAML/C# 将 Windows 应用商店应用置于屏幕中央,包括其所有内容?
我试过这个:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
但是 vertical alignment
似乎不起作用,网格停留在屏幕顶部。
编辑: 我希望红色部分位于屏幕中央:
<Grid RequestedTheme="Light" Loaded="Grid_Loaded" Background="{ThemeResource AppBarItemBackgroundThemeBrush}">
<Grid.Resources>
<Storyboard x:Name="FadeImageStoryboard">
<DoubleAnimation From="0"
To="1"
Duration="0:0:0.7"
Storyboard.TargetName="BackgroundImage"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</Grid.Resources>
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Image Source="assets/113h.jpg" Stretch="Fill" x:Name="BackgroundImage" RequestedTheme="Light" Margin="0,-10,0,10" />
<Button x:Name="backButton" Style="{StaticResource NavigationBackButtonNormalStyle}"
Margin="23,45,0,0"
VerticalAlignment="Top"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" Click="backButton_Click"/>
<StackPanel x:Name="Container">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Margin="363,172,368,308" PlaceholderText="Last Name" BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="LastName"/>
<Button Content="Sign-Up" HorizontalAlignment="Left" Margin="360,417,0,0" VerticalAlignment="Top" Width="257" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
</Grid>
</StackPanel>
</Grid>
您的 Grid
包裹在 StackPanel
中。这意味着它在堆栈面板 中居中 。考虑到 StackPanel
的工作原理,这并没有多大意义。
取出 Grid
(使其成为根 Grid
的子项),居中将按您预期的方式工作。
<Grid RequestedTheme="Light" Loaded="Grid_Loaded" Background="{ThemeResource AppBarItemBackgroundThemeBrush}">
...
//No StackPanel!
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Margin="363,172,368,308" PlaceholderText="Last Name" BorderBrush="#FF755CB0" BorderThickness="1" Opacity="0.9" x:Name="LastName"/>
<Button Content="Sign-Up" HorizontalAlignment="Left" Margin="360,417,0,0" VerticalAlignment="Top" Width="257" Height="50" Background="#FF235085" BorderBrush="#FF6749AC" BorderThickness="1" Foreground="White" Opacity="0.9" RequestedTheme="Light" Click="Register_Click"/>
</Grid>
....
</Grid>