【问题标题】:Windows Phone Flyout stays always on topWindows Phone Flyout 始终位于首位
【发布时间】:2014-11-08 02:09:20
【问题描述】:

Windows Phone SDK (WP 8.1) 的 Flyout 控件无法正常工作。

无论我如何更改 Placement 属性,唯一改变的就是 PlacementMode.Full。 顶部、底部、左侧和右侧仍将弹出按钮保持在显示屏顶部。 还有其他方法可以在我的页面底部显示弹出窗口吗?例如,Microsoft 的日历应用程序在通过按 CommandBar 的右 AppBarButton 更改视图时具有这种确切的行为。

我尝试了以下两种方法:

XAML:
<Page.Resources>
    <Flyout x:Key="MyFlyout">
        <StackPanel>
            <TextBlock Text="Test"/>
        </StackPanel>
    </Flyout>
</Page.Resources>

C#:
Flyout flyout = (Flyout) this.Resources["MyFlyout"];
flyout.Placement = FlyoutPlacementMode.Bottom;
flyout.ShowAt(this.LayoutRoot);

XAML:
<Button Content="ShowFlyout">
    <Button.Flyout>
        <Flyout Placement="Bottom">
            <StackPanel>
                <TextBlock Text="Test"/>
            </StackPanel>
        </Flyout>
    </Button.Flyout>
</Button>

【问题讨论】:

    标签: c# windows xaml windows-phone-8.1 flyout


    【解决方案1】:

    在您编辑问题以包含屏幕截图后,它会变得更加清晰。

    他们使用的是 MenuFlyout,而不仅仅是普通的弹出窗口。

    这可以很容易地在下面的代码中:

    <Page.BottomAppBar>
        <CommandBar Background="Black" IsOpen="False" IsSticky="False" ClosedDisplayMode="Minimal">
            <CommandBar.PrimaryCommands>
                <AppBarButton x:Name="btnPin" Label="Choose" Icon="Calendar" Foreground="White">
                    <Button.Flyout>
                        <MenuFlyout Placement="Top">
                            <MenuFlyoutItem Text="Day" /><MenuFlyoutSeparator/>
                            <MenuFlyoutItem Text="Week" /><MenuFlyoutSeparator/>
                            <MenuFlyoutItem Text="Month" />
                            <MenuFlyoutSeparator/>
                            <MenuFlyoutItem Text="Year" />
                            <MenuFlyoutSeparator/>
                        </MenuFlyout>
                    </Button.Flyout>
                </AppBarButton>                
            </CommandBar.PrimaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
    

    当然,你可以按照你想要的方式来设计它。

    【讨论】:

    • 谢谢,这很酷。有没有办法改变入口过渡?我读了这篇文章,但除了故事板动画之外,没有什么真正有帮助的。但是作为 MenuFlyout 一部分的入口转换仍然存在。 msdn.microsoft.com/en-us/library/windows/apps/xaml/…
    • @Cort3vl 最好为此添加一个新问题,以便社区对此提供帮助。
    • @Cort3vl 此外,如果答案有帮助,请将其标记为答案。
    • 我正在尝试产生与 @Cort3vl 相同的结果,但我认为 MS 没有使用 MenuFlyout,您可以在电子邮件应用程序中看到与日历中相同的行为(点击回复按钮)。当您使用 Flyout 时,您可以看到应用程序被动画到背景,而日历中不是这种情况。 MenuFlyout 与您将手指放在列表中的项目上时效果相同。对我来说,它看起来更像是一个“自定义”视图。
    【解决方案2】:

    有一个简单的解决方法,但它看起来并不是最好的方法。 您可以创建一个针对 FlyoutPresenter 的 Style 并设置边距以强制 Flyout 在底部显示,您需要将 Margin 与一个转换器绑定,该转换器获取屏幕的宽度和高度并设置边距以将弹出窗口向下移动到每个屏幕尺寸的页面。它确实有效,但正如我所说,这似乎不是最好的方法。

    【讨论】:

      【解决方案3】:

      我只是稍微修改了您的代码以在底部显示弹出窗口。

      <Grid>
          <Button x:Name="DeleteButton" Content="Empty cart">
              <Button.Flyout>
                  <Flyout Placement="Full">
                      <Grid VerticalAlignment="Bottom" >
                          <Grid.RowDefinitions>
                              <RowDefinition Height="*"></RowDefinition>
                              <RowDefinition Height="Auto"></RowDefinition>
                              <RowDefinition Height="Auto"></RowDefinition>
                          </Grid.RowDefinitions>
                          <TextBlock Grid.Row="1" Style="{StaticResource BaseTextBlockStyle}">
                              All items will be permanently removed from your cart.
                          </TextBlock>
                          <Button Grid.Row="2" Click="DeleteConfirmation_Click" Margin="0">
                              Empty my cart
                          </Button>
                      </Grid>                        
                  </Flyout>
              </Button.Flyout>
          </Button>
      </Grid>
      

      来自这篇文章:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn308515.aspx

      在 Windows Phone 上,Flyout 默认显示在屏幕顶部。您可以将 Placement 属性更改为 FlyoutPlacementMode.Full 以使弹出窗口覆盖全屏。 Top、Bottom、Left 和 Right 值在 Windows Phone 应用程序中没有任何影响。

      【讨论】:

      • 感谢您的回复。这不是我想要的。我在上面的问题中添加了屏幕截图。也许他们使用了不同的控件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2018-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多