C# DataTemplate错误WP 8.1上的弹出按钮

C# DataTemplate错误WP 8.1上的弹出按钮,c#,listbox,windows-phone-8.1,contextmenu,flyout,C#,Listbox,Windows Phone 8.1,Contextmenu,Flyout,我有一个列表框项目的数据模板。我希望,当用户持有一个列表框项目时,该项目上会出现一个打开的附加弹出按钮,带有一些选项。因此,在调试模式下,当我持有listbox的一项时,我输入了该方法,但它崩溃了,告诉我该元素没有附加的弹出框,但有。。。当我使用自定义DataTemplateSelector时,DataTemplate作为资源写入App.xaml中。这是ListBoxItem的数据模板: <DataTemplate x:Key="FollowerOuterTemplate">

我有一个列表框项目的数据模板。我希望,当用户持有一个列表框项目时,该项目上会出现一个打开的附加弹出按钮,带有一些选项。因此,在调试模式下,当我持有listbox的一项时,我输入了该方法,但它崩溃了,告诉我该元素没有附加的弹出框,但有。。。当我使用自定义DataTemplateSelector时,DataTemplate作为资源写入App.xaml中。这是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>
确切错误为:System.ArgumentException:参数不正确。
ShowAttached是在没有附加弹出式按钮的元素上调用的

是附加到
FollowersList
堆栈面板的
FollowersList\u吗?是的,正如您在xaml中看到的那样。。。。或者我遗漏了什么……不,我没有在你的xaml中看到。你仍然可以,代码将转到App.xaml.cs。但这不是问题所在。在测试时,我也遇到过类似的应用程序崩溃,但是如果我改为使用ListView,问题就会消失。好的,我会尝试使用ListView而不是ListBox,我会让你不断更新!谢谢你的回答!
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)
        {

        }
    }