如何完成“应用程序”按钮和快速访问工具栏放置?
(来源:microsoft.com)
答案 0 :(得分:6)
首先,在xaml中引用Ribbon命名空间...
<r:RibbonWindow
...
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
>
然后您可以通过绑定到ViewModel上的RibbonCommand属性来配置您的应用程序菜单(与绑定其他功能区命令非常相似)
<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;
}
}
对于你问题的第二部分 - 我担心我还没有玩过QuickAccess工具栏,但我猜它会以类似的东西开始......
<r:Ribbon.QuickAccessToolBar>
<r:RibbonQuickAccessToolBar>
<!-- put your RibbonCommands here -->
</r:RibbonQuickAccessToolBar>
</r:Ribbon.QuickAccessToolBar>
答案 1 :(得分:4)
RibbonControl
仅在RibbonWindow
的一部分覆盖窗口顶部框架的显示方式时显示。基本上,Application button
,Quick access toolbar
和Contextual tab
有一个负余量。但是,为了实现这一点,RibbonControl
接管了允许您使用鼠标移动窗口的功能。 Microsoft已发布RibbonControl
作为代码复合的WPF工具包的一部分,尽管它的使用有一定的限制。