0

我想在用户按 F1 时显示帮助文件。如何停止显示默认帮助文件?我做了以下事情:

public static class HelpProvider
{

    #region DependencyProperty [SourceProperty]

    public static readonly DependencyProperty SourceProperty =
        DependencyProperty.RegisterAttached("Source", typeof(string), typeof(HelpProvider),
                                            new PropertyMetadata(OnSourcePropertyChanged));

    public static string GetSource(DependencyObject obj)
    {
        return (string)obj.GetValue(SourceProperty);
    }

    public static void SetSource(DependencyObject obj, string value)
    {
        obj.SetValue(SourceProperty, value);
    }

    public static void OnSourcePropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (e.NewValue == null || !(e.NewValue is string)) return;
        var element = sender as FrameworkElement;
        if (element != null)
            element.KeyDown += element_KeyDown;
    }

    #endregion

    #region Method

    static void element_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key != Key.F1) return;

        e.Handled = true;
        if (GetSource(sender as DependencyObject) != null)
        {
            ShowHelpFile(GetSource(sender as DependencyObject));
        }
    }

    private static void ShowHelpFile(string helpContext)
    {
        if (!DesignerProperties.IsInDesignTool)
        {
            /* Putting the invoking in UIThreadAsync:
             * http://stackoverflow.com/questions/808030/reentrancy-was-detected
             */
            HtmlPage.Window.Invoke("OpenHelpWindow", new object[] { filePath });
        }

    }
    #endregion
}

OpenHelpWindow这是 JS 中打开一个窗口的方法有没有人有想法不显示默认帮助窗口,我很高兴在这里为新设计提供新想法?

谢谢

4

1 回答 1

0

这可能是一个重复的问题。查看以下之前的问题,因为它可能会回答您的问题:如何禁用浏览器的默认帮助功能

尝试以一致的方式在多个浏览器中覆盖 F1 会带来很多问题,因此您最好通过不同的方式提供帮助。

于 2013-09-24T12:31:59.980 回答