BinaryRibbonComboBox
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 | |
|---|---|
BinaryRibbonComboBox | Creates a ribbon drop-down list with no entries. |
| 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. |
DropDownListContentWindowHeight | Gets or sets the height of the scrolling list in the drop-down, not counting
DropDownHeaderContent and DropDownFooterContent. |
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 item that is not a ComboBoxItem – for this control a new
BinaryRibbonComboBox. |
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. |
DropDownListContentWindowHeightProperty | Identifies the DropDownListContentWindowHeight dependency property. |
ImageProperty | Identifies the Image dependency property. |
TitleTextProperty | Identifies the TitleText dependency property. |
Constructors
BinaryRibbonComboBox
Creates a ribbon drop-down list with no entries.
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 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
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.
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
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 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
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
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.
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
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.
DropDownListContentWindowHeightProperty static
Identifies the DropDownListContentWindowHeight dependency property.
ImageProperty static
Identifies the Image dependency property.
TitleTextProperty static
Identifies the TitleText dependency property.