如何强制 RibbonButton 始终启用?

发布于 2024-09-27 17:22:02 字数 1117 浏览 4 评论 0原文

我在窗口内有一个 Microsoft Ribbonbar,每个 RibbonButton 都与一个特定命令相关联,如下所示:

<ribbon:Ribbon x:Key="MyToolbar"  Name="MyToolbar"  >         
<ribbon:RibbonTab Header="File" >
<ribbon:RibbonGroup Header="File"  >
<ribbon:RibbonButton Command="{x:Static ApplicationCommands.New}"  LargeImageSource="Images/GenericDocument.png" Label="Nuovo" />
<ribbon:RibbonButton Command="{x:Static ApplicationCommands.Open}" SmallImageSource="Images/OpenFolder.png" Label="Apri"  />
</ribbon:RibbonGroup>
</ribbon:RibbonTab>
</ribbon:Ribbon>

我以这种方式将命令处理到放置在同一窗口中的特定 Canvas 对象的代码隐藏中:

private void BindApplicationCommands()
{
// FILE group
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed,Open_Enabled));
}

当我单击放置处理代码的 Canvas 组件外部时,功能区内的所有按钮都会禁用。 这是一种不受欢迎的行为,因为我希望某些特定按钮(例如“新建”和“打开”命令)始终全局启用,无论我在哪里单击。 我怎样才能做到这一点? 预先感谢您的任何建议。

I have a Microsoft Ribbonbar inside a Window, and every RibbonButton is associated to a specific command like this:

<ribbon:Ribbon x:Key="MyToolbar"  Name="MyToolbar"  >         
<ribbon:RibbonTab Header="File" >
<ribbon:RibbonGroup Header="File"  >
<ribbon:RibbonButton Command="{x:Static ApplicationCommands.New}"  LargeImageSource="Images/GenericDocument.png" Label="Nuovo" />
<ribbon:RibbonButton Command="{x:Static ApplicationCommands.Open}" SmallImageSource="Images/OpenFolder.png" Label="Apri"  />
</ribbon:RibbonGroup>
</ribbon:RibbonTab>
</ribbon:Ribbon>

I'm handling the commands in this way into the code-behind of a specific Canvas object placed in the same window:

private void BindApplicationCommands()
{
// FILE group
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed,Open_Enabled));
}

When I click outside the Canvas component where the handling code is placed, all the buttons inside the Ribbon become to be disabled.
This is an undesired behaviour, since i want that some specific buttons (like the "New" and "Open" commands) are always and globally enabled, despite to where i click.
How can I achieve this ?
Thanks in advance for any suggestion.

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

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

发布评论

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

评论(1

小瓶盖 2024-10-04 17:22:02

好吧,我解决了我自己的问题。
由于 CommandBindings 是在 Canvas 组件内部定义的,因此它们无法在更广泛的(全局)上下文中进行管理,因此我将它们移至 Window 代码隐藏中,以更灵活的方式委托它们的执行/激活。
就这样 :)

Ok, I solved my own problem.
Since the CommandBindings where defined inside the Canvas component, they weren't manageable into a wider (global) context, so i moved them into the Window code-behind to delegate their execution/activation in a more flexible way.
That's all :)

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