locked
Flyout options for ListView in Hub Control (problem with getting ListViev index)

    Question

  • Hi,

    I have ListView with List source. I would like to create flyout to control list by ListView - I mean, when I hold ListViewItem (StackPanel) in ListView, there is a flyout which have option for ex. delete. When I tap delete I want to delete the exact item in List as I holded in ListView.

    Sounds easy? But the biggest problem is that this ListView is in Hub Control and it is inside <DataTemplate> so I am not able to access to ListView values by calling it from name in C#

    <HubSection x:Uid="Sectionworldclock" x:Name="Sectionworldclock" Header="Sectionworldclock 1">
                            <HubSection.DataContext>
                                <local:WorldClocks/>
                            </HubSection.DataContext>
                            <DataTemplate>
                                <ListView ItemsSource="{Binding}" x:Name="listviewWC" Holding="listviewWC_Holding" SelectionMode="Single" >
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Vertical" Holding="StackPanel_Holding">
                                                <FlyoutBase.AttachedFlyout>
                                                    <MenuFlyout>
                                                        <MenuFlyoutItem x:Uid="EditMenuFlyoutItem" Text="Menu option 1" Click="MenuFlyoutItem_Click" />
                                                        <MenuFlyoutItem x:Uid="DeleteMenuFlyoutItem" Text="Second command" Click="MenuFlyoutItem_Click_1" />
                                                    </MenuFlyout>
                                                </FlyoutBase.AttachedFlyout>
    
                                                <Grid  Height="120" Margin="0" VerticalAlignment="Top">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="17*"/>
                                                        <RowDefinition Height="7*"/>
                                                    </Grid.RowDefinitions>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="8*"/>
                                                        <ColumnDefinition Width="2*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock Margin="0" TextWrapping="Wrap" Text="{Binding ActualTime}" FontSize="73.333" FontFamily="Segoe WP SemiLight" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                                                    <TextBlock Margin="0" Grid.Row="1" TextWrapping="Wrap" Text="{Binding City}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="21.333"/>
                                                </Grid>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
    </DataTemplate>
    </HubSection>
    private void StackPanel_Holding(object sender, HoldingRoutedEventArgs e)
            {
                
                var lv1 = (ListView)((StackPanel)sender).Parent;
                
    
                FrameworkElement senderElement = sender as FrameworkElement;
                FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement);
    
                flyoutBase.ShowAt(senderElement);
            }
    


     Does anybody know how to do that?

    Thx in advise

    Sunday, August 24, 2014 8:35 PM

Answers