I have a listbox, For each list box item I need to display a context menu item based on the data it is bound to. here is my listbox
<ListBox x:Name="pdflist" ItemsSource="{Binding}" Margin="18,0,7,0" SelectionChanged="pdflist_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="mymenu" ItemsSource={Binding}>
<toolkit:ContextMenu.ItemTemplate>
<DataTemplate>
<toolkit:MenuItem Header="{Binding isFavorite}" Click="favorite_Click" />
</DataTemplate>
</toolkit:ContextMenu.ItemTemplate>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<Grid Width="420">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"></ColumnDefinition>
<ColumnDefinition Width="350"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image VerticalAlignment="Top" Margin="0,20,0,0" Height="20" Width="25" Source="/Assets/PDF.png" Grid.Column="0" Stretch="None" >
</Image>
<TextBlock TextWrapping="Wrap" Grid.Column="1" Foreground="Black" FontSize="30" Text="{Binding name}"></TextBlock>
<Image Height="20" Width="25" Grid.Column="2" Source="{Binding isFavorite,Converter={StaticResource typeconvert}}"></Image>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The data bound to list box has the model
public class resources
{
public string name
{
get;
set;
}
public bool isRead { get; set; }
public bool isFavorite { get; set; }
}
When I run my code,I am unable to view any menu items in context menu..
I have tried this
<ItemsControl ItemsSource="{Binding isFavorite}" Tag="{Binding ElementName=pdflist, Path=DataContext}">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}" Click="favorite_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</ItemsControl>
On long press, context menu itself doesnt appear!!