12 Star 110 Fork 36

LunarSF/LunarMind

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
WPF提供帮助文档.txt 4.18 KB
一键复制 编辑 原始数据 按行查看 历史
帮助模块:HelpProvider想用的可以去msdn上查一查,不过这货是windows.forms里的东西,不能在wpf里面用,坑爹呢啊这是,不过在网上找到了一个高人应该算是在wpf里重写了这个HelpProvider,这就让我们写wpf的也可以好好用了,代码经过测试,妥妥的。
namespace ContextSensitiveHelp
{
/// <summary>
/// This class provides the ability to easily attach Help functionality to Framework elements.
/// To use it, you need to add a reference to the HelpProvider in your XAML.
/// The FilenameProperty specifies the name of the help file, and the KeywordProperty specifies the keyword to be used with the search.
/// </summary>
/// <remarks>
/// The FilenameProperty can be at a higher level of the visual tree than the KeywordProperty, so you don't need to set the filename each time.
/// </remarks>
static class HelpProvider
{
static HelpProvider()
{
CommandManager.RegisterClassCommandBinding(typeof(FrameworkElement),
new CommandBinding(ApplicationCommands.Help,
new ExecutedRoutedEventHandler(Executed),
new CanExecuteRoutedEventHandler(CanExecute)));
}
#region Filename
/// <summary>
/// Filename Attached Dependency Property
/// </summary>
public static readonly DependencyProperty FilenameProperty =
DependencyProperty.RegisterAttached("Filename", typeof(string), typeof(HelpProvider));
/// <summary>
/// Gets the Filename property.
/// </summary>
public static string GetFilename(DependencyObject d)
{
return (string)d.GetValue(FilenameProperty);
}
/// <summary>
/// Sets the Filename property.
/// </summary>
public static void SetFilename(DependencyObject d, string value)
{
d.SetValue(FilenameProperty, value);
}
#endregion
#region Keyword
/// <summary>
/// Keyword Attached Dependency Property
/// </summary>
public static readonly DependencyProperty KeywordProperty =
DependencyProperty.RegisterAttached("Keyword", typeof(string), typeof(HelpProvider));
/// <summary>
/// Gets the Keyword property.
/// </summary>
public static string GetKeyword(DependencyObject d)
{
return (string)d.GetValue(KeywordProperty);
}
/// <summary>
/// Sets the Keyword property.
/// </summary>
public static void SetKeyword(DependencyObject d, string value)
{
d.SetValue(KeywordProperty, value);
}
#endregion
#region Event
private static void CanExecute(object sender, CanExecuteRoutedEventArgs args)
{
FrameworkElement el = sender as FrameworkElement;
if (el != null)
{
string fileName = FindFilename(el);
if (!string.IsNullOrEmpty(fileName))
args.CanExecute = true;
}
}
private static void Executed(object sender, ExecutedRoutedEventArgs args)
{
// Call ShowHelp.
DependencyObject parent = args.OriginalSource as DependencyObject;
string keyword = GetKeyword(parent);
if (!string.IsNullOrEmpty(keyword))
{
System.Windows.Forms.Help.ShowHelp(null, FindFilename(parent), keyword);
}
else
{
System.Windows.Forms.Help.ShowHelp(null, FindFilename(parent));
}
}
private static string FindFilename(DependencyObject sender)
{
if (sender != null)
{
string fileName = GetFilename(sender);
if (!string.IsNullOrEmpty(fileName))
return fileName;
return FindFilename(VisualTreeHelper.GetParent(sender));
}
return null;
}
#endregion
}
}
不解释,自己看,毫无压力。在前台页面里加上下面这句话就好
xmlns:h="clr-namespace:ContextSensitiveHelp"
h:HelpProvider.Filename="Help1.chm" h:HelpProvider.Keyword="button.html"
同时一定要把帮助文档放到bin\debug里面去,不一定非得是.chm的,word也可以的。
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/lunarsf/lunarmind.git
git@gitee.com:lunarsf/lunarmind.git
lunarsf
lunarmind
LunarMind
master

搜索帮助