DataOmplate上的FlyOut错误WP 8.1

时间:2014-12-09 21:25:23

标签: c# listbox windows-phone-8.1 contextmenu flyout

我有一个ListBox项的DataTemplate。我希望当用户持有一个列表框项目时,会在项目上显示一个打开的附加弹出窗口,其中包含一些选项。因此,当我拿着列表框的一个项目时,在调试模式下,我输入方法但它崩溃告诉我没有附加到该元素的flyoutBase,但是有...当我使用自定义DataTemplateSelector时,DataTemplate被写入App.xaml作为资源。这是我对ListBoxItem的DataTemplate:

<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>

这是我叫做的方法:

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)
        {

        }
    }

确切的错误是: System.ArgumentException:参数不正确。 在没有附加FlyoutBase的元素上调用ShowAttached

0 个答案:

没有答案