【问题标题】:Disply a Dialog box for user input in a Win 8 Store XAML app在 Win 8 Store XAML 应用程序中显示用户输入对话框
【发布时间】:2012-11-18 01:01:44
【问题描述】:

有没有办法在 Win 8 Store XAML 应用程序中实现类似对话框的效果;类似于in this post 所示的那个,其中对话框的内容是一个用于收集用户输入的自定义控件。

这里是一些示例 XAML 内容,我想以类似于上面帖子中所示的内容居中显示。

<common:LayoutAwarePage
x:Class="App1.UserControls.Control1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
mc:Ignorable="d"
>

<Grid HorizontalAlignment="Stretch" Background="Gold" VerticalAlignment="Center">
    <StackPanel  VerticalAlignment="Center" HorizontalAlignment="Center" AreScrollSnapPointsRegular="True" Margin="20">
        <TextBlock Text="This is sample text" FontSize="20" Style="{StaticResource HeaderTextStyle}"/>            
        <Button Content="Close" Click="btnClose_Click" Margin="0,20,0,0" HorizontalAlignment="Right"/>
    </StackPanel>
</Grid></common:LayoutAwarePage>

我正在使用 Popup 控件从主页面显示此内容,如下所示:

<common:LayoutAwarepage>
<Grid Style="{StaticResource LayoutRootStyle}">
   <Popup x:Name="ParentedPopup" VerticalOffset="300" HorizontalOffset="200" 
    HorizontalAlignment="Stretch">
            <usercontrols:CreateCategory/>
   </Popup>
 </Grid>
<Page.BottomAppBar>
    <AppBar x:Name="bottomAppBar" Padding="10,0,10,0">
        <Grid>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                <Button Style="{StaticResource AddAppBarButtonStyle}" Click="AddButton_Click"/>

            </StackPanel>
        </Grid>
    </AppBar>
</Page.BottomAppBar></common:LayoutAwarePage>
private void AddButton_Click(object sender, RoutedEventArgs e)
{
    if (!ParentedPopup.IsOpen) { ParentedPopup.IsOpen = true; }
}

但是,这并没有按我的意愿显示,弹出窗口没有显示居中的 xaml 内容,它显示在顶部并且没有按我的意愿居中和拉伸。

有没有简单的方法来实现这一点? 注意:我不想依赖任何库。

【问题讨论】:

    标签: windows-8 windows-runtime winrt-xaml


    【解决方案1】:

    如果它们解决了您的问题,为什么您不想依赖任何二进制文件?看一下Callisto,它有一个CustomDialog,它会为您执行此操作,如文档中所示-https://github.com/timheuer/callisto/wiki/CustomDialog。它是开源的,因此您也可以使用源代码。但是您要么依赖某人对您的代码回答,要么依赖二进制文件:-)

    【讨论】:

      【解决方案2】:

      将垂直偏移分配给屏幕的高度

      popup.VerticalOffset = (Window.Current.Bounds.Height / 2) - popup.ActualHeight / 2;
      Width = Window.Current.Bounds.Width;
      
      VerticalAlignment="Center";
      

      还有

      <Grid>
          <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="*" x:Name="ContentColumn"/>
              <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>
      
          <Grid.RowDefinitions>
              <RowDefinition />
              <RowDefinition />
              <RowDefinition />
          </Grid.RowDefinitions>
      
      //Place content in "ContentColumn" to center it
      <Grid>
      

      ContentColumn中的内容放在中间。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-09
        • 1970-01-01
        • 1970-01-01
        • 2014-12-10
        • 1970-01-01
        • 2010-11-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多