InputDialog定位问题

时间:2014-12-05 10:39:42

标签: 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"
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>

在我的代码后面,我有这个功能用于&#34;点击=&#34; OnAddButtonClick&#34;&#34;

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);
....

但是当我按下添加按钮时,输入对话框总是出现在屏幕的中央,即使我尝试添加垂直对齐和边距。 我确实错过了一些愚蠢的东西

如何让它出现在顶部?

1 个答案:

答案 0 :(得分:0)

您应该在致电VerticalAlignment之前设置MarginShowAsync