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 が呼び出されました