如何强制 RibbonButton 始终启用?
我在窗口内有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我解决了我自己的问题。
由于 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 :)