Click or drag to resize

ShellFilePreviewLoadPreview Event

Event is thrown when a file is previewed. It can be implemented to control some aspects of the ShellFilePreview based on the current file or to set a custom preview control.

Namespace:  Jam.Shell.WPF.Controls
Assembly:  ShellBrowserWPF (in ShellBrowserWPF.dll) Version: 1.3.1
Syntax
public event EventHandler<LoadPreviewEventArgs> LoadPreview

Value

Type: SystemEventHandlerLoadPreviewEventArgs
Examples
This example shows how to use the HTML preview handler for files with the extensions CSM:
C#
private static Guid MS_HTML_PREVIEW = new Guid("F8B8412B-DEA3-4130-B36C-5E8BE73106AC");
private void ShellFilePreview1_LoadPreview(object sender, LoadPreviewEventArgs e)
{
    if (string.IsNullOrEmpty(e.Path))
        return;
    if (".cms".Equals(System.IO.Path.GetExtension(e.Path), StringComparison.OrdinalIgnoreCase))
        e.PreviewHandlerGuid = MS_HTML_PREVIEW;
}
Typical identifiers for PreviewHandlers can be found in the registry (HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers)
Examples
The following example loads cs files in a scrollable textbox. Note the usage of SetCustomPreviewHandler(UIElement) and RemoveCustomPreviewHandler.
C#
private void ShellFilePreview_LoadPreview(object sender, LoadPreviewEventArgs e)
{
    string file = e.Path;
    if (String.IsNullOrEmpty(file))
    {
        return;
    }

    if (".cs".Equals(System.IO.Path.GetExtension(file), StringComparison.OrdinalIgnoreCase))
    {
        e.CustomPreviewHandler = new CustomPreviewHandler();
    }
    else if (e.PreviewHandlerGuid == null)
    {
        //add actions to take if no registered PreviewHandler is available.
    }
}

#region ShellFilePreview_LoadPreview
private static Guid MS_HTML_PREVIEW = new Guid("F8B8412B-DEA3-4130-B36C-5E8BE73106AC");
private void ShellFilePreview1_LoadPreview(object sender, LoadPreviewEventArgs e)
{
    if (string.IsNullOrEmpty(e.Path))
        return;
    if (".cms".Equals(System.IO.Path.GetExtension(e.Path), StringComparison.OrdinalIgnoreCase))
        e.PreviewHandlerGuid = MS_HTML_PREVIEW;
}
#endregion

private class CustomPreviewHandler : IShellPreviewHandler
{
    private ShellFilePreview m_Parent;
    public bool Load(ICommonPreviewHandlerHost p_Parent, string p_Path, ItemIdList p_AbsolutePidl)
    {
        m_Parent = (p_Parent as ShellFilePreview);
        ScrollViewer lScroll = new ScrollViewer();
        TextBox lTextBox = new TextBox();
        lTextBox.Text = System.IO.File.ReadAllText(p_Path);
        lScroll.Content = lTextBox;

        m_Parent.SetCustomPreviewHandler(lScroll);
        return true;
    }

    public void Resize() { }

    public void Show() { }

    public void Unload() { m_Parent.RemoveCustomPreviewHandler(); }
}

public void Dispose()
{
    shellFilePreview.Dispose();
}
See Also