FlyOut error in DataTemplate WP 8.1

I have a DataTemplate for ListBox items. I would like that when the user holds down a list item, an open Attached Flyout appears on the item with some parameters. So when I hold a list item, in debug mode, I enter the method, but it crashes, telling me that there is no flyoutBase attached to that item, but there is ... When I use the Custom DataTemplateSelector, the DataTemplate is written to the App. xaml as a resource. This is my DataTemplate for the ListBoxItem:

<DataTemplate x:Key="FollowerOuterTemplate">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" >
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Name="FollowersList">
                <FlyoutBase.AttachedFlyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Delete" />
                        <MenuFlyoutItem Text="Refresh" />
                        <MenuFlyoutItem Text="Share" />
                    </MenuFlyout>
                </FlyoutBase.AttachedFlyout>
                <StackPanel Orientation="Vertical" Width="282">
                    <TextBlock Grid.Row="0" FontSize="33" Text="{Binding Pseudo}" Foreground="Gray" Height="46" Margin="0,0,-0.333,0"/>
                    <TextBlock Grid.Row="1" FontSize="20" Text="{Binding NomPrenom}" Foreground="#5bc5eb" Height="27" Margin="0,0,-0.333,0"/>
                    <TextBlock Grid.Row="2" FontSize="20" Text="Restez appuyer pour bloquer" Foreground="#BCC6CC" Height="27" Margin="0,0,-0.333,0"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Width="113">
                    <Image Name="StatutContact"  Height="43" Source="/Ressources/Images/checkedTests2.png" Stretch="Fill" Margin="0,20,0,0" Width="44" HorizontalAlignment="Center"/>
                </StackPanel>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

      

And here is my method:

private void FollowersList_Holding(object sender, HoldingRoutedEventArgs e)
    {
        try
        {
            FrameworkElement senderElement = sender as FrameworkElement;
            FrameworkElement element = sender as FrameworkElement;
            if (element == null) return;

            // If the menu was attached properly, we just need to call this handy method
            FlyoutBase.ShowAttachedFlyout(element);
        }
        catch (Exception ex)
        {

        }
    }

      

Exact error: System.ArgumentException: The parameter is invalid. ShowAttached is called on an element with no FlyoutBase attached

+3


source to share





All Articles