FlyOut on DataTemplate error WP 8.1

739 Views Asked by At

I have a DataTemplate for the ListBox Items. I would like that when the user holds a listbox item, a open Attached Flyout appears upon the item with some options. So when I hold an item of the listbox, in debug mode, I enter the method but it crashes telling me that there's no flyoutBase attached to that element, but there is... As I use a Custom DataTemplateSelector, the DataTemplate is written in 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 called 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)
        {

        }
    }

The exact error is : System.ArgumentException: The parameter is incorrect. ShowAttached was called on an element without an attached FlyoutBase

0

There are 0 best solutions below