gpt4 book ai didi

WPF:功能区控制应用程序按钮和快速访问工具栏位置

转载 作者:行者123 更新时间:2023-12-04 14:03:57 25 4
gpt4 key购买 nike

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

最佳答案

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

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

然后您可以通过绑定(bind)到 ViewModel 上的 RibbonCommand 属性来配置您的应用程序菜单(与绑定(bind)其他 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;
}
}

对于您问题的第二部分-恐怕我还没有使用 QuickAccess 工具栏玩太多,但我猜它会以类似...
<r:Ribbon.QuickAccessToolBar>
<r:RibbonQuickAccessToolBar>
<!-- put your RibbonCommands here -->
</r:RibbonQuickAccessToolBar>
</r:Ribbon.QuickAccessToolBar>

关于WPF:功能区控制应用程序按钮和快速访问工具栏位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1894398/

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