【问题标题】:Flyout menu in UWP with MVVM带有 MVVM 的 UWP 中的弹出菜单
【发布时间】:2016-11-16 08:57:59
【问题描述】:

我正在尝试在按住 GridView 的项目时打开的 Windows 10 应用程序(使用 MVVM)中实现弹出菜单。我一直在寻找,但找不到任何适合我的例子。弹出菜单未打开以显示选项。有谁知道我该怎么做?

<GridView.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <FlyoutBase.AttachedFlyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}"/>
                    </MenuFlyout>
            </FlyoutBase.AttachedFlyout>
            <Image Source="{Binding Dictionary}" Height="25"/>
            <TextBlock Text="{Binding Title}" Foreground="White" Width="170"/>
        </StackPanel>
    </DataTemplate>
</GridView.ItemTemplate>

注意:解决方案见https://marcominerva.wordpress.com/2013/12/17/using-a-behavior-to-open-attached-flyouts-in-winows-81-store-apps/

【问题讨论】:

  • 你的代码在哪里?我们如何调试这个问题?
  • 对不起,忘记粘贴了

标签: mvvm uwp windows-10-universal flyout


【解决方案1】:

我认为您要设置的是 StackPanel.Flyout 而不是 FlyoutBase

<GridView.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <StackPanel.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}"/>
                    </MenuFlyout>
            </StackPanel.Flyout>
            <Image Source="{Binding Dictionary}" Height="25"/>
            <TextBlock Text="{Binding Title}" Foreground="White" Width="170"/>
        </StackPanel>
    </DataTemplate>
</GridView.ItemTemplate>

或者,如果这对您不起作用,您可以定位 GridViewItem.Flyout

<GridView>
   <GridView.Resources>
      <Style TargetType="GridViewItem">
          <Setter Property="Flyout">
             <Setter.Value>
                <MenuFlyout>
                   <MenuFlyoutItem Text="Delete" Command="{Binding DeleteCommand}"/>
                </MenuFlyout>
             </Setter.Value>
          </Setter>
      </Style>
</Gridview.Resources>

【讨论】:

  • 我都尝试了,但出现以下错误:无法识别或无法访问成员“Flyout”。我通过创建一个操作找到了解决方案:marcominerva.wordpress.com/2013/12/17/… 无论如何谢谢 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-22
  • 1970-01-01
  • 2010-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多