Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Ribbon control application button and quick access toolbar location

How is the Application button and quick access toolbar placement accomplished? alt text
(source: microsoft.com)

like image 403
Brad Avatar asked Dec 29 '22 08:12

Brad


1 Answers

first, put a reference to the Ribbon namespace in your xaml...

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

then you can configure your Application menu by binding to a RibbonCommand property on your ViewModel (much the same as you bind your other Ribbon commands)

<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>

where the property looks something like:

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;
    }
}

For the second part of your question - I'm afraid I haven't played too much with the QuickAccess toolbar yet, but I'm guessing it will start with something like...

<r:Ribbon.QuickAccessToolBar>
    <r:RibbonQuickAccessToolBar>
     <!-- put your RibbonCommands here -->
    </r:RibbonQuickAccessToolBar>
</r:Ribbon.QuickAccessToolBar>
like image 199
kiwipom Avatar answered May 27 '23 17:05

kiwipom