C# 输入对话框定位问题

C# 输入对话框定位问题,c#,xaml,windows-runtime,windows-store-apps,C#,Xaml,Windows Runtime,Windows Store Apps,在windows应用商店应用程序中,我有以下页面 <common:LayoutAwarePage x:Class="Gapp_metro.Pages.DocumentsPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Gapp_metro.Pages"

在windows应用商店应用程序中,我有以下页面

<common:LayoutAwarePage
x:Class="Gapp_metro.Pages.DocumentsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Gapp_metro.Pages"
xmlns:common="using:Gapp_metro.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

<Grid Style="{StaticResource RootGridStyle}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
        <RowDefinition Height="50" />
    </Grid.RowDefinitions>

    <Grid Style="{StaticResource HeaderGridStyle}" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Button Click="GoBack" IsEnabled="{Binding Frame.CanGoBack}" Style="{StaticResource BackButtonStyle}" />
        <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}" />
    </Grid>

    <Grid Grid.Row="1" Style="{StaticResource ContentGridStyle}" VerticalAlignment="Center">
        <GridView x:Name="gridView" Grid.Row="1" ItemsSource="{Binding Tiles}" Style="{StaticResource GridViewStyle}" ItemClick="OnItemClick" />

        <ListView x:Name="listView" Grid.Row="1" ItemsSource="{Binding Tiles}" Style="{StaticResource ListViewStyle}" ItemClick="OnItemClick"
                  Visibility="Collapsed" />

        <ProgressRing x:Name="ProgressR" Grid.Row="1" IsActive="{Binding IsLoading}" />
    </Grid>

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ApplicationViewStates">
            <VisualState x:Name="FullScreenLandscape" />
            <VisualState x:Name="Filled"/>
            <VisualState x:Name="FullScreenPortrait" />
            <VisualState x:Name="Snapped">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>

<Page.BottomAppBar>
    <AppBar x:Name="appBar" Style="{StaticResource AppBarStyle}">
        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
            <Button Click="OnAddButtonClick" Style="{StaticResource AddAppBarButtonStyle}" />
            <Button Click="OnUploadButtonClick" Style="{StaticResource UploadAppBarButtonStyle}" />
            <Button Click="OnPhotoButtonClick" Style="{StaticResource PhotoAppBarButtonStyle}" />
        </StackPanel>
    </AppBar>
</Page.BottomAppBar>
但当我按下“添加”按钮时,输入对话框总是出现在屏幕中央,即使我试图添加垂直对齐和边距。 我肯定我错过了一些愚蠢的事情


如何使其显示在顶部?

在调用
ShowAsync
之前,您应该设置
VerticalAlignment
Margin

private async void OnAddButtonClick(object sender, RoutedEventArgs e)
    {
        var dialog = new InputDialog();
        dialog.BackgroundStripeBrush = new SolidColorBrush(Color.FromArgb(255, 149, 191, 0));
        dialog.Background = new SolidColorBrush(Color.FromArgb(255, 149, 191, 0));
        dialog.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 149, 191, 0));
        Style buttonStyle = new Style() { TargetType = typeof(Button) };
        buttonStyle.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
        dialog.ButtonStyle = buttonStyle;
        var result = await dialog.ShowAsync(App.Current.Resources["createFolder"] as String, App.Current.Resources["newFolderName"] as String, App.Current.Resources["create"] as String, App.Current.Resources["close"] as String);

        dialog.VerticalAlignment = VerticalAlignment.Top;
        dialog.Margin = new Thickness(0, 0, 0, 0);
....