HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonComboBox

BinaryRibbonComboBox

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

A drop-down list for the ribbon, with an optional caption beside it and room for your own content above and below the list – a font size box, a style picker, a list of saved views.

public class BinaryRibbonComboBox : ComboBox, IBinaryRibbonComponentCanRenderInReducedSizeState, IBinaryRibbonComponentCanDisplayImage, IBinaryRibbonComponent, IBinaryRibbonComponentCanStretchAndBeRotated, IBinaryRibbonKeyTipControl

Inherits from / implements: ComboBox, IBinaryRibbonComponentCanRenderInReducedSizeState, IBinaryRibbonComponentCanDisplayImage, IBinaryRibbonComponent, IBinaryRibbonComponentCanStretchAndBeRotated, IBinaryRibbonKeyTipControl

Remarks

It is a WPF ComboBox, so Selector.SelectedItem, Selector.SelectedIndex, Selector.SelectionChanged and ComboBox.IsEditable behave as usual.

Entries

Add BinaryRibbonComboBoxItem objects (or plain ComboBoxItem objects) to ItemsControl.Items; a BinaryRibbonComboBoxItem can carry a small picture. A data object given through ItemsControl.ItemsSource is wrapped in a new BinaryRibbonComboBox rather than in an item (see GetContainerForItemOverride), so it does not appear as an ordinary entry.

Layout

TitleText is the caption to the left of the box and ContentWidth the width of the box itself. When the ribbon draws the control small the caption is hidden, and when its group folds into a drop-down the control is hidden. The list area is a fixed DropDownListContentWindowHeight tall and scrolls; DropDownHeaderContent and DropDownFooterContent sit above and below it.

Keyboard

A key tip (BinaryKeyTip.AccessKeyProperty) opens the list, or closes it if it is open.

Examples

A font size box with a caption, in a Font group.

<ribbon:BinaryRibbonGroup TitleText="Font"
        xmlns:ribbon="clr-namespace:Binarymission.WPF.Controls.Office;assembly=Binarymission.WPF.Controls.BinaryRibbon">
    <ribbon:BinaryRibbonComboBox x:Name="fontSizeBox"
                                 TitleText="Size"
                                 ContentWidth="56"
                                 SelectedIndex="2"
                                 ribbon:BinaryKeyTip.AccessKey="FS"
                                 SelectionChanged="OnFontSizeChanged">
        <ribbon:BinaryRibbonComboBoxItem Content="9" />
        <ribbon:BinaryRibbonComboBoxItem Content="10" />
        <ribbon:BinaryRibbonComboBoxItem Content="11" />
        <ribbon:BinaryRibbonComboBoxItem Content="12" />
        <ribbon:BinaryRibbonComboBoxItem Content="14" />
        <ribbon:BinaryRibbonComboBoxItem Content="18" />
    </ribbon:BinaryRibbonComboBox>
</ribbon:BinaryRibbonGroup>
private void OnFontSizeChanged(object sender, SelectionChangedEventArgs e)
{
    var entry = fontSizeBox.SelectedItem as BinaryRibbonComboBoxItem;
    if (entry != null)
    {
        noteEditor.FontSize = double.Parse((string)entry.Content) * 96.0 / 72.0;
    }
}

See also

Members at a glance

Constructors
BinaryRibbonComboBoxCreates a ribbon drop-down list with no entries.
Properties
BinaryRibbonTagGets or sets any object of your own to keep with the control.
ContentWidthGets or sets the width of the box itself – the selection and its drop-down arrow – not counting the caption.
DropDownFooterContentGets or sets content shown under the list in the drop-down – a "More..." button, a hint, a link to settings.
DropDownFooterContentDataTemplateGets or sets the template that draws DropDownFooterContent when it is a data object rather than a UI element.
DropDownHeaderContentGets or sets content shown above the list in the drop-down – a heading, a search box, a "Recently used" label.
DropDownHeaderContentDataTemplateGets or sets the template that draws DropDownHeaderContent when it is a data object rather than a UI element.
DropDownListContentWindowHeightGets or sets the height of the scrolling list in the drop-down, not counting DropDownHeaderContent and DropDownFooterContent.
ImageGets or sets a picture to associate with the control.
TitleTextGets or sets the caption shown to the left of the box – "Size", "Style", "Font".
Methods
GetContainerForItemOverrideCreates the container for an item that is not a ComboBoxItem – for this control a new BinaryRibbonComboBox.
IsItemItsOwnContainerOverrideReports whether an item is shown as it stands: true for a BinaryRibbonComboBoxItem or any other ComboBoxItem.
OnDropDownClosedRaises ComboBox.DropDownClosed, then the DropDownClosedAndRibbonToRefreshHandler routed event.
Events
DropDownClosedAndRibbonToRefreshHandlerOccurs each time the list closes, whether or not the selection changed.
Fields
ContentWidthPropertyIdentifies the ContentWidth dependency property.
DropDownClosedAndRibbonToRefreshIdentifies the DropDownClosedAndRibbonToRefreshHandler routed event.
DropDownFooterContentDataTemplatePropertyIdentifies the DropDownFooterContentDataTemplate dependency property.
DropDownFooterContentPropertyIdentifies the DropDownFooterContent dependency property.
DropDownHeaderContentDataTemplatePropertyIdentifies the DropDownHeaderContentDataTemplate dependency property.
DropDownHeaderContentPropertyIdentifies the DropDownHeaderContent dependency property.
DropDownListContentWindowHeightPropertyIdentifies the DropDownListContentWindowHeight dependency property.
ImagePropertyIdentifies the Image dependency property.
TitleTextPropertyIdentifies the TitleText dependency property.

Constructors

BinaryRibbonComboBox

public BinaryRibbonComboBox() : base()

Creates a ribbon drop-down list with no entries.

Properties

BinaryRibbonTag

public object BinaryRibbonTag

Gets or sets any object of your own to keep with the control.

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.

ContentWidth

public double ContentWidth

Gets or sets the width of the box itself – the selection and its drop-down arrow – not counting the caption.

Value
The width in device-independent units (1/96 inch). The default is NaN, which sizes the box to its content.
Remarks

Set it so that a column of boxes on the ribbon line up, or so that the box does not change width as the selection changes. FrameworkElement.Width is the width of the whole control, caption included.

See also

DropDownFooterContent

public object DropDownFooterContent

Gets or sets content shown under the list in the drop-down – a "More..." button, a hint, a link to settings.

Value
Any content: a UI element, or an object drawn by DropDownFooterContentDataTemplate. The default is null, which shows nothing.
See also

DropDownFooterContentDataTemplate

public DataTemplate DropDownFooterContentDataTemplate

Gets or sets the template that draws DropDownFooterContent when it is a data object rather than a UI element.

Value
The template. The default is null, which shows a data object as its text.

DropDownHeaderContent

public object DropDownHeaderContent

Gets or sets content shown above the list in the drop-down – a heading, a search box, a "Recently used" label.

Value
Any content: a UI element, or an object drawn by DropDownHeaderContentDataTemplate. The default is null, which shows nothing.
See also

DropDownHeaderContentDataTemplate

public DataTemplate DropDownHeaderContentDataTemplate

Gets or sets the template that draws DropDownHeaderContent when it is a data object rather than a UI element.

Value
The template. The default is null, which shows a data object as its text.

DropDownListContentWindowHeight

public double DropDownListContentWindowHeight

Gets or sets the height of the scrolling list in the drop-down, not counting DropDownHeaderContent and DropDownFooterContent.

Value
The height in device-independent units (1/96 inch). The default is 100.
Remarks

The list is always this tall, however few entries there are, and scrolls when they need more. The whole drop-down is still capped by ComboBox.MaxDropDownHeight.

Image

public ImageSource Image

Gets or sets a picture to associate with the control.

Value
The picture. The default is null.
Remarks

The control's built-in template does not draw it; it is there for a template of your own, and for code that treats ribbon controls alike through IBinaryRibbonComponentCanDisplayImage.

TitleText

public string TitleText

Gets or sets the caption shown to the left of the box – "Size", "Style", "Font".

Value
The caption. The default is an empty string, which shows no caption.
Remarks

The caption is hidden while the ribbon draws the control at BinaryRibbonControlSize.Small, which is how a crowded group saves width.

See also

Methods

GetContainerForItemOverride

protected override DependencyObject GetContainerForItemOverride()

Creates the container for an item that is not a ComboBoxItem – for this control a new BinaryRibbonComboBox.

Returns

A new, empty BinaryRibbonComboBox.

Remarks

Because the container is a combo box and not an item, a string or data object added to the control is not shown as an ordinary entry. Add BinaryRibbonComboBoxItem objects instead, with the text in ContentControl.Content.

IsItemItsOwnContainerOverride

protected override bool IsItemItsOwnContainerOverride(object item)

Reports whether an item is shown as it stands: true for a BinaryRibbonComboBoxItem or any other ComboBoxItem.

Parameters
item
The item.
Returns

true when item is a ComboBoxItem; otherwise false, and a container is made for it.

OnDropDownClosed

protected override void OnDropDownClosed(EventArgs e)
Parameters
e
The data for the event.

Events

DropDownClosedAndRibbonToRefreshHandler

public event RoutedEventHandler DropDownClosedAndRibbonToRefreshHandler

Occurs each time the list closes, whether or not the selection changed.

Remarks

A bubbling routed event, raised after ComboBox.DropDownClosed.

The BinaryRibbonBarPanel above the control handles it to close its own pop-ups – the drop-down of a group that has folded away, or the ribbon dropped over the document while it is minimised – so that choosing an entry there puts the ribbon away as well.

To act on the user's choice, handle Selector.SelectionChanged instead.

Fields

ContentWidthProperty static

public static readonly DependencyProperty ContentWidthProperty

Identifies the ContentWidth dependency property.

DropDownClosedAndRibbonToRefresh static

public static readonly RoutedEvent DropDownClosedAndRibbonToRefresh

Identifies the DropDownClosedAndRibbonToRefreshHandler routed event.

DropDownFooterContentDataTemplateProperty static

public static readonly DependencyProperty DropDownFooterContentDataTemplateProperty

Identifies the DropDownFooterContentDataTemplate dependency property.

DropDownFooterContentProperty static

public static readonly DependencyProperty DropDownFooterContentProperty

Identifies the DropDownFooterContent dependency property.

DropDownHeaderContentDataTemplateProperty static

public static readonly DependencyProperty DropDownHeaderContentDataTemplateProperty

Identifies the DropDownHeaderContentDataTemplate dependency property.

DropDownHeaderContentProperty static

public static readonly DependencyProperty DropDownHeaderContentProperty

Identifies the DropDownHeaderContent dependency property.

DropDownListContentWindowHeightProperty static

public static readonly DependencyProperty DropDownListContentWindowHeightProperty

Identifies the DropDownListContentWindowHeight dependency property.

ImageProperty static

public static readonly DependencyProperty ImageProperty

Identifies the Image dependency property.

TitleTextProperty static

public static readonly DependencyProperty TitleTextProperty

Identifies the TitleText dependency property.