HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonLivePreview

BinaryRibbonLivePreview

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

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

EventRaised when, and what to do

PreviewRequestedEvent

The pointer rests on an item. Show the document as it would be with BinaryRibbonLivePreviewEventArgs.Item. Remember how it was first, if this is the first request since the last cancel or commit.

PreviewCancelledEvent

The pointer has left the items, or the user pressed Escape. Put the document back as it was.

PreviewCommittedEvent

An item has been chosen. Apply BinaryRibbonLivePreviewEventArgs.Item for good.

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
AddPreviewCancelledHandlerAdds a handler for the PreviewCancelledEvent, to be told when a preview should be undone.
AddPreviewCommittedHandlerAdds a handler for the PreviewCommittedEvent, to be told when an item has been chosen.
AddPreviewRequestedHandlerAdds a handler for the PreviewRequestedEvent, to be told when the user rests the pointer on an item.
RemovePreviewCancelledHandlerRemoves a handler added with AddPreviewCancelledHandler.
RemovePreviewCommittedHandlerRemoves a handler added with AddPreviewCommittedHandler.
RemovePreviewRequestedHandlerRemoves a handler added with AddPreviewRequestedHandler.
Fields
PreviewCancelledEventIdentifies 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.
PreviewCommittedEventIdentifies the PreviewCommitted attached routed event, raised when the user has chosen an item and its effect should stay.
PreviewRequestedEventIdentifies 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

public static void AddPreviewCancelledHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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 UIElement is ignored.
handler
The handler to add.

AddPreviewCommittedHandler static

public static void AddPreviewCommittedHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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 UIElement is ignored.
handler
The handler to add.

AddPreviewRequestedHandler static

public static void AddPreviewRequestedHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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 UIElement is ignored.
handler
The handler to add.

RemovePreviewCancelledHandler static

public static void RemovePreviewCancelledHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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

public static void RemovePreviewCommittedHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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

public static void RemovePreviewRequestedHandler( DependencyObject element, EventHandler<BinaryRibbonLivePreviewEventArgs> handler)

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

public static readonly RoutedEvent 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.

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

public static readonly RoutedEvent PreviewCommittedEvent

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

public static readonly RoutedEvent 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.

Remarks

Bubbles. BinaryRibbonLivePreviewEventArgs.Item is the item under the pointer – for a gallery, its BinaryRibbonGallery.MouseOverItem. Moving to another item raises a new request.

See also