1
votes

In my databound (somewhat advanced) ListBox, I have a context menu implemented. When I tap and hold a ListBoxItem, though, the ContextMenu basically just pops up - without the nice little drop-down animation - the first time I do that on an ListBoxItem. The second time (and every time after that) it works fine.

I don't even know how to debug this - anybody got any ideas?

Here's some example XAML:

<ListBox ItemsSource="{Binding ItemList}" Margin="0,0,0,30" ScrollViewer.VerticalScrollBarVisibility="Hidden" x:Name="TodayList" SelectionChanged="handler">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <ListBoxItem>
                <StackPanel Height="88" Margin="12,0,0,0">
                    <toolkit:ContextMenuService.ContextMenu>
                        <toolkit:ContextMenu BorderBrush="Black" Background="Black">
                            <toolkit:MenuItem Header="choice1" Foreground="White" Click="handler" />
                            <toolkit:MenuItem Header="choice2" Foreground="White" Click="handler" />
                            <toolkit:MenuItem Header="choice3" Foreground="White" Click="handler" />
                            <toolkit:MenuItem Header="choice4" Foreground="White" Click="handler" />
                        </toolkit:ContextMenu>
                     </toolkit:ContextMenuService.ContextMenu>
                     <TextBlock Style="{StaticResource YellowMedium}" Margin="0,0,0,-4" Text="{Binding Title}" />
                     <TextBlock Style="{StaticResource SubtleText}" Text="{Binding TimeOnChannel}" />
                 </StackPanel>
             </ListBoxItem>
         </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>
1
Which kind of listbox do you use?RredCat

1 Answers

0
votes

there is a difference I have removed the ListBoxItem tag from datatemplate try this

<ListBox ItemsSource="{Binding ItemList}" Margin="0,0,0,30" ScrollViewer.VerticalScrollBarVisibility="Hidden" x:Name="TodayList" SelectionChanged="handler">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="88" Margin="12,0,0,0">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu BorderBrush="Black" Background="Black">
<toolkit:MenuItem Header="choice1" Foreground="White" Click="handler" />
<toolkit:MenuItem Header="choice2" Foreground="White" Click="handler" />
<toolkit:MenuItem Header="choice3" Foreground="White" Click="handler" />
<toolkit:MenuItem Header="choice4" Foreground="White" Click="handler" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Style="{StaticResource YellowMedium}" Margin="0,0,0,-4" Text="{Binding Title}" />
 <TextBlock Style="{StaticResource SubtleText}" Text="{Binding TimeOnChannel}" />
 </StackPanel>
 </DataTemplate>
 </ListBox.ItemTemplate>
 </ListBox>