【问题标题】:WPF: Ribbon control application button and quick access toolbar locationWPF:功能区控制应用程序按钮和快速访问工具栏位置
【发布时间】:2010-12-26 01:10:38
【问题描述】:

应用程序按钮和快速访问工具栏的放置是如何完成的?
(来源:microsoft.com

【问题讨论】:

    标签: wpf xaml button controls


    【解决方案1】:

    RibbonControl 仅在 RibbonWindow 的一部分覆盖窗口顶部框架的显示方式时才会显示。基本上,Application buttonQuick access toolbarContextual tab 具有负边距。但是,要使其正常工作,RibbonControl 接管了允许您使用鼠标移动窗口的功能。 Microsoft 已将 RibbonControl 作为 codeplex 上 WPF 工具包的一部分发布,尽管它的使用有一定的限制。

    【讨论】:

    • 谢谢克劳斯。我去拿工具包。
    【解决方案2】:

    首先,在您的 xaml 中放置对 Ribbon 命名空间的引用...

    <r:RibbonWindow
            ...
        xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            >
    

    然后您可以通过绑定到 ViewModel 上的 RibbonCommand 属性来配置您的应用程序菜单(与绑定其他 Ribbon 命令非常相似)

    <r:Ribbon>
        <r:Ribbon.ApplicationMenu>
            <r:RibbonApplicationMenu
                Command="{Binding Path=ApplicationMenuCommand}">
    
            <!-- If your first menu item if 'Open File' -->
                <r:RibbonApplicationMenuItem
                    Command="{Binding Path=OpenFileCommand}" />
    
            </r:RibbonApplicationMenu>
        </r:Ribbon.ApplicationMenu>
    </r:Ribbon>
    

    属性看起来像这样的地方:

    public RibbonCommand OpenFileCommand
    {
        get
        {
            if (_openFileCommand == null)
            {
                _openFileCommand = new RibbonCommand("OpenFileCommand", typeof(RibbonApplicationMenuItem));
                _openFileCommand.LabelDescription = "Label Description";
                _openFileCommand.LabelTitle = "Label Title";
                _openFileCommand.ToolTipDescription = "Tooltip Description";
                _openFileCommand.ToolTipTitle = "Tooltip Title";
    
                _openFileCommand.CanExecute += (sender, e) => { e.CanExecute = true; };
                _openFileCommand.Executed += (sender, e) => { /* logic to open a file goes here... */; };
            }
            return _openFileCommand;
        }
    }
    

    对于您问题的第二部分 - 恐怕我还没有玩太多快速访问工具栏,但我猜它会以类似...

    <r:Ribbon.QuickAccessToolBar>
        <r:RibbonQuickAccessToolBar>
         <!-- put your RibbonCommands here -->
        </r:RibbonQuickAccessToolBar>
    </r:Ribbon.QuickAccessToolBar>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2017-04-29
      • 1970-01-01
      相关资源
      最近更新 更多