我有一个带有相同类型子项的 RibbonApplicationMenuItem。子项由代码添加。
选择 RibbonApplicationMenuItem 后,在处理单击事件时会显示错误的 currentItem。
CurrentItem 始终是我的 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 包含单击的 MenuItem,但我连接的对象丢失。SenderApplicationMenu 包含带有名为 CurrentItem 的属性的 corrospondig ParentMenuItem。
事件在主要元素的功能区窗口的 XAML 代码中分配:
<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>
在这种情况下,CurrentItem 始终包含具有对应对象的第一个 SubItem。有任何想法吗 ?