This is the code snippet..the click in the button works but on on the XamMenuItem..so I am using button instead of the menuitem (Ihave commented it out)...any ideas..?
<
="xamMenu1_ItemClicked">
="Export" >
="XamMenuItem_Click" />
/>
="To Printer" />
>
="Views" >
="XamMenuItem_Click_Save" />
="XamMenuItem_Click_Load">
<!--<TextBlock Text="{Binding Path=ViewName}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp"/>-->
="2"/>
<!--<menu:XamMenuItem Header="{Binding Path=ViewName}" Click="XamMenuItem_Click_1"></menu:XamMenuItem>-->
Hi,
Basically, when you add objects as children of a menu (or menu item), a new XamMenuItem is generated for each of these objects. If you have specified an ItemTemplate, this item template will be applied as a ContentTemplate on the generated XamMenuItem.
So, if you specify a XamMenuItem as your ItemTemplate, you'll end-up having a generated XamMenuItem with another XamMenuItem set as its ContentTemplate.
If you want to set certain properties (or add event handlers) for all generated XamMenuItems, you should use the DefaultItemsContainer property:
<menu:XamMenuItem Header="Load" x:Name="loadMenuItem" Click="XamMenuItem_Click_Load"> <menu:XamMenuItem.DefaultItemsContainer> <DataTemplate> <menu:XamMenuItem Header="{Binding Path=ViewName}" Click="XamMenuItem_Click_1" /> </DataTemplate> </menu:XamMenuItem.DefaultItemsContainer> </menu:XamMenuItem>
Hope this helps,
That works just fine now.
Out of curisoty when would you use an itemtemplate in this case then ..?
You would use the ItemTemplate to change the appearance of the content in your generated items.
You could read more about the ItemTemplate property here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplate.aspx
The "Remarks" section outlines how the ItemTemplate property works and when you should use it.
Got it.