RibbonApplicationMenuItem 有错误的 CurrentItem?

发布于 2024-11-28 15:33:54 字数 1961 浏览 2 评论 0原文

我有一个带有相同类型子项的 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 包含相应的 ParentMenuItem,其属性名为 CurrentItem。

事件在主元素的功能区窗口的 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。 有什么想法吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-12-05 15:33:54

问题很简单。

SubItems 没有 Click 事件处理程序,因此事件被路由到上层处理程序。

我现在已经为每个项目实现了处理程序,一切都很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文