Reputation: 5375
I got a horizontal ListBox displaying pictures. I wanted to add a ContextMenu on each item allowing the user to delete the item. But I don't know exactly where to put my ContextMenu in my ItemTemplate, I tried approximately everywhere but the ContextMenu never shows on Holding. Do you have an idea where to place the XAML bloc?
<ListBox x:Name="PhotoListBox" Grid.Row="1" ItemsSource="{Binding}" SelectionChanged="PhotoListBox_SelectionChanged" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel
HorizontalAlignment="Left"
Margin="0,0,0,0"
VerticalAlignment="Top"
/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<StackPanel Orientation="Vertical">
<Grid Width="100" Height="100">
<Grid.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="{Binding}" />
</Grid.Background>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Delete" Click="MenuItem_OnClick"/>
</toolkit:ContextMenu>
</Grid>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks
Upvotes: 0
Views: 315
Reputation: 2706
wrap it in within the contextMenuService:
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Delete" Click="MenuItem_OnClick"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
see http://phone.codeplex.com/SourceControl/latest#PhoneToolkitSample/Samples/ContextMenuSample.xaml for a complete sample
Upvotes: 1