gpt4 book ai didi

wpf - WPF 中的关键提示

转载 作者:行者123 更新时间:2023-12-01 01:37:37 25 4
gpt4 key购买 nike

Office 2007 和功能区引入了“Key Tips”的概念。

In short, every single command in theRibbon receives a letter which you canpress to activate that command. ...The letters are indicated by small"KeyTips" which indicate the letter topress to activate the control. KeyTipsare displayed using the Alt key, sousing them feels similar to how menunavigation works in Windows.

(Source: http://blogs.msdn.com/jensenh/archive/2006/04/12/574930.aspx)


关键提示的示例如下所示。在此图中,用户按下了 ALT 键,并正在等待进一步的输入。
Key Tips Example in Word 2007 http://blogs.msdn.com/blogfiles/outlook/WindowsLiveWriter/RibbonKeyTips_8F7C/clip_image002_thumb.jpg
是否有任何“关键提示”的 WPF 开源示例?
您将如何以通用方式(即不需要功能区)实现类似此功能的功能?您将如何使用 MVVM 模式来实现这一点(假设 ICommand 不支持 InputBindings)。
注意:ActiPro 在他们的 Ribbon 的实现中实现了这个功能。 ,但他们还没有发布源代码。

最佳答案

首先,您可以查看 Ribbon Preview在 Microsoft 的 WPF 工具包中。

或者,一种通用方法是这样的:

  • 制作 DependencyProperty在您可以触发的窗口/顶级控件中,例如 IsShowingKeyTips .在您认为合适的时候捕捉键盘输入以翻转它。
  • 制作 ContentControl具有两个依赖属性,例如 1) IsShowingKeyTip和 2) KeyTipText .我们称之为 KeyTipContentControl .
  • 编辑ContentControlControlTemplate看看你想要的样子。让它成为 Canvas或者你最喜欢的布局容器,使用一些绑定(bind)来适本地调整它的大小,也许会抛出一些负面的Margin值(value)观。
  • 如果你想花哨,做一些AttachedProperties喜欢 KeyTip.Text将它们从普通控件冒泡到 KeyTipContentControl .
  • 在您的 XAML 中,将 ContentControls围绕Controls你想要按键提示。根据需要设置绑定(bind)。

  • 你最终会在顶层得到这样的东西:
    <Window ... >
    <code:KeyTipContentControl
    KeyTipText="A"
    IsShowingKeyTip="{Binding IsShowingKeyTips}">
    <Button x:Name="MyButtonWithKeyTip" ... />
    </code:KeyTipContentControl>
    </Window>

    以优雅的方式处理按键并不是我现在想做的事情。 :-)

    关于wpf - WPF 中的关键提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/814756/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com