I have a problem with MenuFlyout. I am trying to get a context menu that works well to give the user the delete and edit options. But if the user clicks on one of these options, there seems to be no decision on how to get the list or the selected item. Maybe I just embarrassed something, but I searched all day, and although people had similar problems, none of the solutions worked for me.
Xaml
<Pivot x:Name="MyPivot" Title="MyTitle" ItemsSource="{Binding}"> <Pivot.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding Title}"/> </DataTemplate> </Pivot.HeaderTemplate> <Pivot.ItemTemplate> <DataTemplate> <ScrollViewer> <ListView x:Name="MyListView" ItemsSource="{Binding Items}"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="Margin" Value="0,0,0,10"/> </Style> </ListView.ItemContainerStyle> <ListView.ItemTemplate> <DataTemplate> <Grid Holding="Grid_Holding"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <FlyoutBase.AttachedFlyout> <MenuFlyout> <MenuFlyoutItem x:Name="EditButton" Text="Edit" Click="EditButton_Click"/> <MenuFlyoutItem x:Name="DeleteButton" Text="Delete" Click="DeleteButton_Click"/> </MenuFlyout> </FlyoutBase.AttachedFlyout> // Content (TextBlocks...) </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> </ScrollViewer> </DataTemplate> </Pivot.ItemTemplate> </Pivot>
FROM#
private void Grid_Holding(object sender, HoldingRoutedEventArgs e) { FrameworkElement senderElement = sender as FrameworkElement; FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement); flyoutBase.ShowAt(senderElement); }
Cort3vl
source share