I've got an RibbonApplicationMenuItem with SubItems of the same Kind. The SubItems are added by Code.
After selecting a RibbonApplicationMenuItem the wrong currentItem is shown while handling the click event.
CurrentItem is always the first element in in my Collection of RibbonApplicationMenuItems.
private void ApplicationOpenPileList_Click(object sender, RoutedEventArgs e) {
RibbonApplicationMenuItem SourceApplicationMenu = null;
RibbonApplicationMenuItem SenderApplicationMenu = null;
Pile currentPile = null;
if (e.OriginalSource != null) {
if (sender is RibbonApplicationMenuItem && e.OriginalSource is RibbonApplicationMenuItem) {
SenderApplicationMenu = sender as RibbonApplicationMenuItem;
SourceApplicationMenu = e.OriginalSource as RibbonApplicationMenuItem;
}
}
}
SourceApplicationMenu contains the clicked MenuItem, but my connected Object is missing. SenderApplicationMenu contains the corrospondig ParentMenuItem whith a property called CurrentItem.
The Event is assigned in XAML Code of the ribbonwindow for the main element:
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu SmallImageSource="Resources\Icons\Scanner.ico">
<ribbon:RibbonApplicationMenuItem Header="Neu" ImageSource="Resources\Icons\report_add.png"/>
<ribbon:RibbonApplicationMenuItem Header="Öffnen" ImageSource="Resources\Icons\open_folder.png" Name="ApplicationOpenPileList" Click="ApplicationOpenPileList_Click" />
<ribbon:RibbonApplicationMenuItem Header="Dokumententypen" ImageSource="Resources\Icons\application_form.png" DisplayMemberPath="Name" Click="RibbonApplicationMenuItem_Click" />
<ribbon:RibbonApplicationMenuItem Header="Schließen" ImageSource="Resources\Icons\cross.png"/>
</ribbon:RibbonApplicationMenu>
</ribbon:Ribbon.ApplicationMenu>
In this case CurrentItem always contains the first SubItem with the correspondig object. Any Ideas ?
Problem was quite simple.
The SubItems hasn't got a Click Event handler, so the events were routed to the upper handler.
I've now implement the handler for each Item and everything is fine.