Hi,
I'm trying to do binding to the ContextMenu and I can't get anything to display. If I replace the ContextMeny by a regulat Menu, then it works as expected.
Here's the XAML that I use:
<igMenu:XamWebMenu ItemsSource="{Binding}"> <igMenu:XamWebMenu.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"/> </DataTemplate> </igMenu:XamWebMenu.ItemTemplate> </igMenu:XamWebMenu> <Image Source="/PopupButtonTest;component/Filter2HS.png" Stretch="None" > <igMenu:ContextMenuService.Manager> <igMenu:ContextMenuManager ModifierKeys="None" OpenMode="LeftClick"> <igMenu:ContextMenuManager.ContextMenu> <igMenu:XamWebContextMenu Placement="AlignedToTheLeft" ItemsSource="{Binding}" > <igMenu:XamWebContextMenu.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"/> </DataTemplate> </igMenu:XamWebContextMenu.ItemTemplate> </igMenu:XamWebContextMenu> </igMenu:ContextMenuManager.ContextMenu> </igMenu:ContextMenuManager> </igMenu:ContextMenuService.Manager> </Image>
Update: I used a menu instead to achieve pretty much the same behaviour. It works just as expected:
<igMenu:XamWebMenu Grid.Column="1" HorizontalAlignment="Right" > <igMenu:XamWebMenu.Items> <igMenu:XamWebMenuItem SubmenuPreferredLocation="Left" ItemsSource="{Binding Data}" > <igMenu:XamWebMenuItem.Icon> <Image Source="/WfW.Infrastructure.Silverlight;component/Images/Filter2HS.png" Stretch="Uniform" /> </igMenu:XamWebMenuItem.Icon> <igMenu:XamWebMenuItem.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" /> </DataTemplate> </igMenu:XamWebMenuItem.ItemTemplate> </igMenu:XamWebMenuItem> </igMenu:XamWebMenu.Items> </igMenu:XamWebMenu>
Is the ContextMenu binding broken?
I attached a sample application demonstarting how to set ItemSource to the ContextMenu using the ContextMenuService
Regards
Thanks. I thought the RelativeSource wouldn't work there.
I'll have try it out if the XamWebMenu doesn't work as I want it to.
Hi,This sample works, but i'm not sure about your scenario<UserControl.Resources> <DataTemplate x:Key="itemTemplate"> <Grid x:Name="theGrid" Background="AliceBlue"> <TextBlock x:Name="textBlock" Text="{Binding}" Margin="2"> <igMenu:ContextMenuService.Manager> <igMenu:ContextMenuManager ModifierKeys="None" OpenMode="LeftClick"> <igMenu:ContextMenuManager.ContextMenu> <igMenu:XamWebContextMenu x:Name="contextMenu1" Placement="AlignedToTheLeft" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext}"> </igMenu:XamWebContextMenu> </igMenu:ContextMenuManager.ContextMenu> </igMenu:ContextMenuManager> </igMenu:ContextMenuService.Manager> </TextBlock> </Grid></DataTemplate></UserControl.Resources><Grid x:Name="LayoutRoot" Background="White" DataContext="ABCDEFG"><ContentControl ContentTemplate="{StaticResource itemTemplate}" Content="{Binding}"/></Grid>Regards,Marin
From your example, I see that your setting the ContextMenu's DataContext in code.
My issue is that I wanted to use the ContextMenu in a DataTemplate within a Style and I obviously cannot have any code-behind there.
How would I get around doing the same with XAML only? Can't I bind it to the current DataContext?
Cheers.