【问题标题】:Flyout Menu windows phone 8.1 on hold Listview弹出菜单 windows phone 8.1 暂停 Listview
【发布时间】:2015-05-06 01:08:31
【问题描述】:

如何在 listview 上使用按住项目时显示 flyout 菜单?我试过了,但是hold方法引用listview而不是它自己的项目。

【问题讨论】:

  • listview 不适用于 WP8。那你说的是WP8.1吗?
  • 是的,先生。更新问题。

标签: c# xaml windows-phone-8.1


【解决方案1】:

您可以订阅项目的模板 Holding 事件。比如这样:

<ListView.ItemTemplate>
    <DataTemplate>
        <Grid Holding="Grid_Holding" VerticalAlignment="Stretch">
            <FlyoutBase.AttachedFlyout>
                <MenuFlyout>
                    <MenuFlyoutItem x:Name="EditButton"
                            Text="Edit"
                            Click="EditButton_Click"/>
                    <MenuFlyoutItem x:Name="DeleteButton"
                            Text="Delete"
                            Click="DeleteButton_Click"/>
                </MenuFlyout>
            </FlyoutBase.AttachedFlyout>
            <TextBlock Text="{Binding}" VerticalAlignment="Center"/>
        </Grid>
    </DataTemplate>
</ListView.ItemTemplate>

在后面的代码中,显示浮出控件:

private void Grid_Holding(object sender, HoldingRoutedEventArgs e)
{
    FrameworkElement senderElement = sender as FrameworkElement;
    // If you need the clicked element:
    // Item whichOne = senderElement.DataContext as Item;
    FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement);
    flyoutBase.ShowAt(senderElement);
}

private async void EditButton_Click(object sender, RoutedEventArgs e)
{
    // get the clicked element:
    Item datacontext = (e.OriginalSource as FrameworkElement).DataContext as Item;
    await new MessageDialog("Edit").ShowAsync();
}

如果您愿意,也可以使用 行为。您还可以通过Igrali's blog post 找到一些帮助。

【讨论】:

  • 谢谢,这很有帮助。
  • @Romasz - 使用整个持有的物品会弹出。是否有任何属性可以将物品保留在原位?
  • @RohitGarg 我不知道。我认为这也是一个很好的问题,所以请在 SO 上提问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多