BinaryRibbonFontFamilyComboBox
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 | |
|---|---|
BinaryRibbonFontFamilyComboBox | Creates a font box. Its default style fills it with the fonts installed on the computer. |
| Properties | |
BinaryRibbonTag | Gets or sets any object of your own to keep with the control. |
ContentWidth | Gets or sets the width of the box itself – the selection and its drop-down arrow – not counting the caption. |
DropDownFooterContent | Gets or sets content shown under the list in the drop-down – a "More..." button, a hint, a link to settings. |
DropDownFooterContentDataTemplate | Gets or sets the template that draws DropDownFooterContent when it is a data object
rather than a UI element. |
DropDownHeaderContent | Gets or sets content shown above the list in the drop-down – a heading, a search box, a "Recently used" label. |
DropDownHeaderContentDataTemplate | Gets or sets the template that draws DropDownHeaderContent when it is a data object
rather than a UI element. |
Image | Gets or sets a picture to associate with the control. |
TitleText | Gets or sets the caption shown to the left of the box – "Size", "Style", "Font". |
| Methods | |
GetContainerForItemOverride | Creates the container for an entry – a font, usually – which for this control is a
BinaryRibbonComboBoxItem. |
IsItemItsOwnContainerOverride | Reports whether an item is shown as it stands: true for a BinaryRibbonComboBoxItem or
any other ComboBoxItem. |
OnDropDownClosed | Raises ComboBox.DropDownClosed, then the
DropDownClosedAndRibbonToRefreshHandler routed event. |
| Events | |
DropDownClosedAndRibbonToRefreshHandler | Occurs each time the list closes, whether or not the selection changed. |
| Fields | |
ContentWidthProperty | Identifies the ContentWidth dependency property. |
DropDownClosedAndRibbonToRefresh | Identifies the DropDownClosedAndRibbonToRefreshHandler routed event. |
DropDownFooterContentDataTemplateProperty | Identifies the DropDownFooterContentDataTemplate dependency property. |
DropDownFooterContentProperty | Identifies the DropDownFooterContent dependency property. |
DropDownHeaderContentDataTemplateProperty | Identifies the DropDownHeaderContentDataTemplate dependency property. |
DropDownHeaderContentProperty | Identifies the DropDownHeaderContent dependency property. |
ImageProperty | Identifies the Image dependency property. |
TitleTextProperty | Identifies the TitleText dependency property. |
Constructors
BinaryRibbonFontFamilyComboBox
Creates a font box. Its default style fills it with the fonts installed on the computer.
Properties
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
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
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 isnull, which shows nothing.
See also
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
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
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
Creates the container for an entry – a font, usually – which for this control is a
BinaryRibbonComboBoxItem.
Returns
A new BinaryRibbonComboBoxItem.
IsItemItsOwnContainerOverride
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
Raises ComboBox.DropDownClosed, then the
DropDownClosedAndRibbonToRefreshHandler routed event.
Parameters
e- The data for the event.
Events
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
Identifies the ContentWidth dependency property.
DropDownClosedAndRibbonToRefresh static
Identifies the DropDownClosedAndRibbonToRefreshHandler routed event.
DropDownHeaderContentDataTemplateProperty static
Identifies the DropDownHeaderContentDataTemplate dependency property.
DropDownHeaderContentProperty static
Identifies the DropDownHeaderContent dependency property.
ImageProperty static
Identifies the Image dependency property.
TitleTextProperty static
Identifies the TitleText dependency property.