BinaryRibbonLivePreview
The routed events a ribbon gallery raises so that an application can show the effect of a choice in its document before the user commits to it, and the methods for handling them.
public static class BinaryRibbonLivePreview
Remarks
Live preview is the ribbon's most recognisable behaviour: the pointer rests on a style and the
document takes it on; the pointer moves away and the document goes back; a click keeps it. Only the
application knows what its document is and how to change it and change it back, so the ribbon
does not do that part. A BinaryRibbonGallery says what the user is pointing at and when
to stop, and the application does the rest.
The three events
| Event | Raised when, and what to do |
|---|---|
The pointer rests on an item. Show
the document as it would be with | |
The pointer has left the items, or the user pressed Escape. Put the document back as it was. | |
An item has been chosen. Apply
|
Order
A request may follow another request, as the pointer moves from item to item, or follow a cancel; treat each as "show this item". A cancel is raised only while a preview is showing. A commit is raised for every selection a gallery makes, including one made from code or the keyboard with no preview before it, so treat it as "apply this item" whatever came first.
Where to listen
All three bubble, so a handler on the gallery hears that gallery alone and a handler on a tab,
the ribbon or the window hears every gallery inside it. Attach handlers in code with the
Add...Handler methods here, or in XAML with
ribbon:BinaryRibbonLivePreview.PreviewRequested="OnPreviewRequested". A gallery raises nothing
while its BinaryRibbonGallery.IsLivePreviewEnabled is false.
Examples
Previewing a table style on the table of an order form. Each thumbnail in the gallery carries
the Style it stands for in its Tag.
private Style styleBeforePreview;
private void HookLivePreview()
{
BinaryRibbonLivePreview.AddPreviewRequestedHandler(tableStyleGallery, (sender, e) =>
{
if (styleBeforePreview == null) styleBeforePreview = orderTable.Style;
orderTable.Style = (Style)((FrameworkElement)e.Item).Tag;
});
BinaryRibbonLivePreview.AddPreviewCancelledHandler(tableStyleGallery, (sender, e) =>
{
if (styleBeforePreview != null) orderTable.Style = styleBeforePreview;
styleBeforePreview = null;
});
BinaryRibbonLivePreview.AddPreviewCommittedHandler(tableStyleGallery, (sender, e) =>
{
orderTable.Style = (Style)((FrameworkElement)e.Item).Tag;
styleBeforePreview = null;
undoHistory.Record("Table style");
});
}See also
Members at a glance
| Methods | |
|---|---|
AddPreviewCancelledHandler | Adds a handler for the PreviewCancelledEvent, to be told when a preview should be undone. |
AddPreviewCommittedHandler | Adds a handler for the PreviewCommittedEvent, to be told when an item has been chosen. |
AddPreviewRequestedHandler | Adds a handler for the PreviewRequestedEvent, to be told when the user rests the pointer on an item. |
RemovePreviewCancelledHandler | Removes a handler added with AddPreviewCancelledHandler. |
RemovePreviewCommittedHandler | Removes a handler added with AddPreviewCommittedHandler. |
RemovePreviewRequestedHandler | Removes a handler added with AddPreviewRequestedHandler. |
| Fields | |
PreviewCancelledEvent | Identifies the PreviewCancelled attached routed event, raised when the user stops pointing at
the items without choosing, and the application should put the document back as it was. |
PreviewCommittedEvent | Identifies the PreviewCommitted attached routed event, raised when the user has chosen an item
and its effect should stay. |
PreviewRequestedEvent | Identifies the PreviewRequested attached routed event, raised when the user rests the pointer
on an item and the application should show what choosing it would do. |
Methods
AddPreviewCancelledHandler static
Adds a handler for the PreviewCancelledEvent, to be told when a preview should be undone.
Parameters
element- The element to listen on: a gallery for that gallery alone, or a tab, ribbon or
window for every gallery inside it. Anything that is not a
UIElementis ignored. handler- The handler to add.
AddPreviewCommittedHandler static
Adds a handler for the PreviewCommittedEvent, to be told when an item has been chosen.
Parameters
element- The element to listen on: a gallery for that gallery alone, or a tab, ribbon or
window for every gallery inside it. Anything that is not a
UIElementis ignored. handler- The handler to add.
AddPreviewRequestedHandler static
Adds a handler for the PreviewRequestedEvent, to be told when the user rests the pointer on an item.
Parameters
element- The element to listen on: a gallery for that gallery alone, or a tab, ribbon or
window for every gallery inside it. Anything that is not a
UIElementis ignored. handler- The handler to add.
RemovePreviewCancelledHandler static
Removes a handler added with AddPreviewCancelledHandler.
Parameters
element- The element the handler was added to.
handler- The handler to remove. Removing one that was never added does nothing.
RemovePreviewCommittedHandler static
Removes a handler added with AddPreviewCommittedHandler.
Parameters
element- The element the handler was added to.
handler- The handler to remove. Removing one that was never added does nothing.
RemovePreviewRequestedHandler static
Removes a handler added with AddPreviewRequestedHandler.
Parameters
element- The element the handler was added to.
handler- The handler to remove. Removing one that was never added does nothing.
Fields
PreviewCancelledEvent static
Identifies the PreviewCancelled attached routed event, raised when the user stops pointing at
the items without choosing, and the application should put the document back as it was.
Remarks
Bubbles. BinaryRibbonLivePreviewEventArgs.Item is null. It is
raised when the pointer leaves the item or the gallery, or when Escape is pressed, and only while a
preview is showing.
See also
PreviewCommittedEvent static
Identifies the PreviewCommitted attached routed event, raised when the user has chosen an item
and its effect should stay.
Remarks
Bubbles. BinaryRibbonLivePreviewEventArgs.Item is the item chosen – for a
gallery, its new SelectedItem. A gallery raises it for every selection it
makes, including one made in code, so it can arrive with no request before it.
See also
PreviewRequestedEvent static
Identifies the PreviewRequested attached routed event, raised when the user rests the pointer
on an item and the application should show what choosing it would do.
Remarks
Bubbles. BinaryRibbonLivePreviewEventArgs.Item is the item under the pointer –
for a gallery, its BinaryRibbonGallery.MouseOverItem. Moving to another item raises a
new request.