浏览器F1按键显示我自己的帮助窗口

时间:2013-09-24 11:47:42

标签: c# javascript silverlight silverlight-4.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中打开窗口的方法 有没有人有想法不显示默认帮助窗口,我会很高兴这里有新设计的新想法吗?

由于

1 个答案:

答案 0 :(得分:0)

这可能是一个重复的问题。请查看以下问题,因为它可以回答您的问题:How to disable default Help function of browsers

尝试以一致的方式在多个浏览器中覆盖F1会遇到问题,因此您可能最好通过其他方式提供帮助。