HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonButton

BinaryRibbonButton

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Office

The ribbon's push button: a command with a picture and a caption that redraws itself large, medium or small as the ribbon gives it room.

public class BinaryRibbonButton : Button, IBinaryRibbonContentElementBoundsConfigurable, IBinaryRibbonKeyTipControl

Inherits from / implements: Button, IBinaryRibbonContentElementBoundsConfigurable, IBinaryRibbonKeyTipControl

Remarks

Use it for any one-click command on a ribbon – Paste, New Invoice, Send, Print. It is an ordinary WPF Button, so Click, Command and CommandParameter work exactly as they do anywhere else.

Pictures and caption

Give it a 32 x 32 LargeImage and a 16 x 16 SmallImage, and put the caption in ContentControl.Content. Large, the button shows the large picture over a caption split across two lines at the space nearest its middle; medium, the small picture with the caption beside it; small, the small picture alone. With no small picture the large one is drawn scaled down in its place, and with no picture at all the caption is centred on the button.

Size

The size is the attached BinaryRibbonBarPanel.SizeProperty, which the BinaryRibbonGroup holding the button sets as the window widens and narrows. Limit it with BinaryRibbonBarPanel.MaxSizeProperty and BinaryRibbonBarPanel.MinSizeProperty, or give the exact size for each step of shrinking with BinaryRibbonBarPanel.ResizableSizeProperty. At BinaryRibbonControlSize.Minimized the button is hidden, because its group has folded into a single drop-down.

Keyboard

Set the attached BinaryKeyTip.AccessKeyProperty and, inside a BinaryRibbonWindow, the button shows that letter when the user presses Alt or F10; typing it focuses the button and clicks it.

Appearance

The border and fill come from the skin in force (BinaryRibbonBuiltInSkinController.Skin), through the BinaryRibbonThemeResources.HighlightedBorderBrushKey and BinaryRibbonThemeResources.RibbonButtonGroupBackgroundBrushKey resources; setting Control.BorderBrush or Control.Background on one button overrides them for that button.

Examples

A Clipboard group with a large Paste button and three medium buttons beside it, in a ribbon window. The images are resources in the application.

<ribbon:BinaryRibbonWindow x:Class="Invoicing.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ribbon="clr-namespace:Binarymission.WPF.Controls.Office;assembly=Binarymission.WPF.Controls.BinaryRibbon"
        Title="Invoicing" Width="1000" Height="640">
    <DockPanel>
        <ribbon:BinaryRibbonBarPanel DockPanel.Dock="Top">
            <ribbon:BinaryRibbonTabItem HeaderText="Home">
                <ribbon:BinaryRibbonGroup TitleText="Clipboard">
                    <ribbon:BinaryRibbonButton Content="Paste"
                                               LargeImage="Images/Paste32.png"
                                               SmallImage="Images/Paste16.png"
                                               ribbon:BinaryKeyTip.AccessKey="V"
                                               Command="ApplicationCommands.Paste" />
                    <ribbon:BinaryRibbonButton Content="Cut" SmallImage="Images/Cut16.png"
                                               ribbon:BinaryRibbonBarPanel.MaxSize="Medium"
                                               ribbon:BinaryKeyTip.AccessKey="X"
                                               Command="ApplicationCommands.Cut" />
                    <ribbon:BinaryRibbonButton Content="Copy" SmallImage="Images/Copy16.png"
                                               ribbon:BinaryRibbonBarPanel.MaxSize="Medium"
                                               ribbon:BinaryKeyTip.AccessKey="C"
                                               Command="ApplicationCommands.Copy" />
                    <ribbon:BinaryRibbonButton Content="Duplicate invoice" SmallImage="Images/Duplicate16.png"
                                               ribbon:BinaryRibbonBarPanel.MaxSize="Medium"
                                               Click="OnDuplicateInvoice" />
                </ribbon:BinaryRibbonGroup>
            </ribbon:BinaryRibbonTabItem>
        </ribbon:BinaryRibbonBarPanel>

        <ContentControl x:Name="invoiceView" />
    </DockPanel>
</ribbon:BinaryRibbonWindow>

The same button made in code and added to a group.

using System;
using System.Windows.Media.Imaging;
using Binarymission.WPF.Controls.Office;

BinaryRibbonButton newInvoice = new BinaryRibbonButton
{
    Content = "New Invoice",
    LargeImage = new BitmapImage(new Uri("pack://application:,,,/Images/NewInvoice32.png")),
    SmallImage = new BitmapImage(new Uri("pack://application:,,,/Images/NewInvoice16.png"))
};
BinaryKeyTip.SetAccessKey(newInvoice, "N");
newInvoice.Click += (sender, e) => invoices.CreateDraft();

invoiceGroup.Controls.Add(newInvoice);

See also

Members at a glance

Properties
BinaryRibbonTagGets or sets any object of your own to keep with the button – the record or command it acts on, say.
CornerRadiusGets or sets how rounded the corners of the button's frame and highlight are.
LargeImageGets or sets the picture the button shows when the ribbon draws it large.
SmallImageGets or sets the picture the button shows when the ribbon draws it medium or small.
Methods
GetImageStretchGets how a button's picture fills the square it is drawn in.
SetImageStretchSets how a button's picture fills the square it is drawn in.
Fields
CornerRadiusPropertyIdentifies the CornerRadius dependency property.
ImageStretchPropertyIdentifies the ImageStretch attached property, which says how a BinaryRibbonButton's picture fills the square it is drawn in.
LargeImagePropertyIdentifies the LargeImage dependency property.
SmallImagePropertyIdentifies the SmallImage dependency property.

Properties

BinaryRibbonTag

public object BinaryRibbonTag

Gets or sets any object of your own to keep with the button – the record or command it acts on, say.

Value
Any object. The default is null.
Remarks

The ribbon never reads it. It is a plain property, not a dependency property, so it cannot be the target of a binding or a style setter; use FrameworkElement.Tag for that.

CornerRadius

public CornerRadius CornerRadius

Gets or sets how rounded the corners of the button's frame and highlight are.

Value
The radius of each corner, in device-independent units (1/96 inch). The default is 3 on every corner.
Remarks

Inside a BinaryRibbonButtonGroup the group sets this itself, rounding only the outer corners of the first and last buttons, so a value set on a button there is replaced.

LargeImage

public ImageSource LargeImage

Gets or sets the picture the button shows when the ribbon draws it large.

Value
The picture, drawn 32 x 32 device-independent units. The default is null.
Remarks

When SmallImage is null, this picture is also used, scaled to 16 x 16, for the medium and small sizes. How it fills its square is set by the attached ImageStretchProperty.

See also

SmallImage

public ImageSource SmallImage

Gets or sets the picture the button shows when the ribbon draws it medium or small.

Value
The picture, drawn 16 x 16 device-independent units. The default is null, which shows LargeImage scaled down instead.
Remarks

When both pictures are null the medium button shows its caption alone, centred. A small button with no picture shows nothing, because a small button has no caption. A large button does not fall back to this picture: give it a LargeImage.

See also

Methods

GetImageStretch static

public static Stretch GetImageStretch(DependencyObject obj)

Gets how a button's picture fills the square it is drawn in.

Parameters
obj
The button to read it from.
Returns

The stretch; Stretch.Uniform unless it has been set.

See also

SetImageStretch static

public static void SetImageStretch(DependencyObject obj, Stretch value)

Sets how a button's picture fills the square it is drawn in.

Parameters
obj
The button to set it on.
value
The stretch. Stretch.None draws the picture at its own size, which suits a small glyph that would blur if scaled.
See also

Fields

CornerRadiusProperty static

public static readonly DependencyProperty CornerRadiusProperty

Identifies the CornerRadius dependency property.

ImageStretchProperty static

public static readonly DependencyProperty ImageStretchProperty

Identifies the ImageStretch attached property, which says how a BinaryRibbonButton's picture fills the square it is drawn in.

Remarks

The default is Stretch.Uniform: the whole picture, as large as fits, in its own proportions. It is attached rather than an ordinary property so that it can be set in XAML on the button (ribbon:BinaryRibbonButton.ImageStretch="None") or in a style.

LargeImageProperty static

public static readonly DependencyProperty LargeImageProperty

Identifies the LargeImage dependency property.

SmallImageProperty static

public static readonly DependencyProperty SmallImageProperty

Identifies the SmallImage dependency property.