Hello,
Here is my code:
<Menus:XamMenuItem x:Name="mnuChartType" ItemsSource="{Binding GalleryTypes}"> <Menus:XamMenuItem.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20"/> <ColumnDefinition /> </Grid.ColumnDefinitions> <Image Source="{Binding Converter={StaticResource ctImageConv}}" Grid.Column="0" Height="14" Width="15" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Text="{Binding}" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/> </Grid> </DataTemplate> </Menus:XamMenuItem.ItemTemplate> </Menus:XamMenuItem>
In application menu looks like this. And question is on picture :) How do I put icons on right places?
And almost forgot. How do I subscribe to click events on each menu item in databound menus?
Thank you.
Thank you very much, this works fine
Hi,
You should set the image to the Icon property of the children. So, your code should look something like this:
<Menus:XamMenuItem x:Name="mnuChartType" ItemsSource="{Binding GalleryTypes}"> <Menus:XamMenuItem.DefaultItemsContainer> <DataTemplate> <Menus:XamMenuItem> <Menus.XamMenuItem.Icon> <Image Source="{Binding Converter={StaticResource ctImageConv}}" /> </Menus.XamMenuItem.Icon> </Menus:XamMenuItem> </DataTemplate> </Menus:XamMenuItem.DefaultItemsContainer> </Menus:XamMenuItem>
<Menus:XamMenuItem x:Name="mnuChartType" ItemsSource="{Binding GalleryTypes}">
<Menus:XamMenuItem.DefaultItemsContainer> <DataTemplate> <Menus:XamMenuItem> <Menus.XamMenuItem.Icon> <Image Source="{Binding Converter={StaticResource ctImageConv}}" /> </Menus.XamMenuItem.Icon> </Menus:XamMenuItem> </DataTemplate> </Menus:XamMenuItem.DefaultItemsContainer> </Menus:XamMenuItem>
As for your second question, I'd recommend using the ItemClicked event of the Xammenu instead of subscribing for the Click event of each MenuItem.
Hope this helps,