HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonFontFamilyComboBox

BinaryRibbonFontFamilyComboBox

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

A ribbon drop-down that lists every font installed on the computer, ready to use as a Font box.

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

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

Remarks

Its style fills ItemsControl.ItemsSource with SystemFontFamilies and selects the first of them, so it works with no setup; Selector.SelectedItem is then a FontFamily. The fonts come in no particular order; give the control a sorted list of your own through ItemsControl.ItemsSource if order matters. Each entry is shown in a BinaryRibbonComboBoxItem.

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. DropDownHeaderContent and DropDownFooterContent sit above and below the list, which scrolls.

Keyboard

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

Examples

<ribbon:BinaryRibbonGroup TitleText="Font"
        xmlns:ribbon="clr-namespace:Binarymission.WPF.Controls.Office;assembly=Binarymission.WPF.Controls.BinaryRibbon">
    <ribbon:BinaryRibbonFontFamilyComboBox x:Name="fontBox"
                                           ContentWidth="160"
                                           ribbon:BinaryKeyTip.AccessKey="FF"
                                           SelectionChanged="OnFontChanged" />
</ribbon:BinaryRibbonGroup>
private void OnFontChanged(object sender, SelectionChangedEventArgs e)
{
    var family = fontBox.SelectedItem as FontFamily;
    if (family != null)
    {
        letterEditor.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, family);
    }
}

See also

Members at a glance

Constructors
BinaryRibbonFontFamilyComboBoxCreates a font box. Its default style fills it with the fonts installed on the computer.
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.
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 entry – a font, usually – which for this control is a BinaryRibbonComboBoxItem.
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.
ImagePropertyIdentifies the Image dependency property.
TitleTextPropertyIdentifies the TitleText dependency property.

Constructors

BinaryRibbonFontFamilyComboBox

public BinaryRibbonFontFamilyComboBox() : base()

Creates a font box. Its default style fills it with the fonts installed on the computer.

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 the selected font's name.
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.

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 entry – a font, usually – which for this control is a BinaryRibbonComboBoxItem.

Returns

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

This is a different routed event from BinaryRibbonComboBox.DropDownClosedAndRibbonToRefresh, and the BinaryRibbonBarPanel listens only for that one, so choosing a font in a folded group's drop-down does not close that drop-down by itself.

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.

ImageProperty static

public static readonly DependencyProperty ImageProperty

Identifies the Image dependency property.

TitleTextProperty static

public static readonly DependencyProperty TitleTextProperty

Identifies the TitleText dependency property.