我有一个chm用于我的应用程序,我想附加我的应用程序,当用户按F1附带的项目帮助打开时。
答案 0 :(得分:6)
我不知道在WPF中构建支持以显示CHM文件。我所做的是添加一个InputGesture将F1键击连接到Application.Help命令,并在Windows CommandBindings中添加一个Application.Help命令的处理程序。以下是示例代码:
<Window x:Class="WpfTestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" >
<Window.InputBindings>
<KeyBinding Command="Help" Key="F1"/>
</Window.InputBindings>
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Help" Executed="HelpExecuted" />
</Window.CommandBindings>
<Grid>
</Grid>
这是处理程序代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
{
System.Diagnostics.Process.Start(@"C:\MyProjectPath\HelpFile.chm");
}
}
答案 1 :(得分:0)
答案 2 :(得分:0)
基于这种方法,我做了以下工作,因此我可以利用我通过RelayCommand管理帮助的OnlineHelpViewModel。当按下F1时,使用这种方法,调用viewmodel上的RelayCommand就好像ia一样?按钮被推了。换句话说,我们将F1绑定到RelayCommand。
此示例使用GalaSoft MvvmLight。
DependencyProperty on the MainWindow
public static DependencyProperty HelpCommandProperty = DependencyProperty.Register("HelpCommand",
typeof(RelayCommand<string>), typeof(WindowExt),
new PropertyMetadata(null));
public RelayCommand<string> HelpCommand
{
get
{
return (RelayCommand<string>)GetValue(HelpCommandProperty);
}
set
{
SetValue(HelpCommandProperty, value);
}
}
确定保存命令
现在在窗口加载的事件或你喜欢的地方:
...
Binding b2 = new Binding();
b2.Source = ViewModelLocator.OnlineHelpViewModelStatic;
b2.Path = new PropertyPath("ShowApplicationHelpCommand");
b2.Mode = BindingMode.OneWay;
this.SetBinding(HelpCommandProperty, b2);
var kb = new KeyBinding();
kb.Key = Key.F1;
kb.Command = HelpCommand;
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, HelpCommand_Executed));
确定将SOURCE视图模型上的命令绑定到此窗口。
然后在这个窗口上执行命令的处理程序(也许这可以以某种方式内联)
private void HelpCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
this.HelpCommand.Execute(HelpContextGuid);
}
现在你可以从任何地方调用OnlineHelpViewModel上的单个帮助命令,它也可以任意复杂。请注意,传递了DP HelpContextGuid - 由命令决定如何处理它,但RelayCommmand&lt; string&gt;想要一个论点
命令本身看起来像(在SOURCE Viewmodel上)
...
ShowApplicationHelpCommand = new RelayCommand<string>(
(h) => { ShowApplicationHelp(h); },
(h) => CanShowApplicationHelpCommand);
...
它调用的方法是显示帮助所需的一切,
就我而言,我创建了一个RadWindow等,并使用BackSpin Software HelpLoader使用XamlHelp填充它。帮助文件是从Word与Twister4Word生成的。 所有这一切都是我的应用程序特有的,所以你可能会做一些其他的事情来建立一个帮助窗口。这是构造函数:
public MigratorHelpWindow()
{
// create local resources for desingn mode, so Blend can see the viewmodels
if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{
App.CreateStaticResourcesForDesigner(this);
}
InitializeComponent();
if (Application.Current.MainWindow != null)
{
var thm = ThemeManager.FromName(Application.Current.FindResource("TelerikGlobalTheme").ToString() ?? "Office_Blue");
StyleManager.SetTheme(this, thm);
}
// window configuration
MaxHeight = SystemParameters.WorkArea.Height;
MaxWidth = SystemParameters.WorkArea.Width;
Binding b = new Binding();
b.Source = ViewModelLocator.OnlineHelpViewModelStatic;
b.Path = new PropertyPath("ApplicationHelpFileName");
b.Mode = BindingMode.OneWay;
this.SetBinding(ApplicationHelpFileNameProperty, b);
if (String.IsNullOrEmpty(ApplicationHelpFileName))
{
UiHelpers.ShowError("No help file is available", true);
return;
}
// LOAD YOUR HELP HERE OR WHATEVER
// LOAD YOUR HELP HERE OR WHATEVER
// LOAD YOUR HELP HERE OR WHATEVER
HelpLoader.Load(ApplicationHelpFileName);
HelpLoader.Default.Owner = this;
HelpLoader.Default.HelpLayout = HelpLayout.Standard;
HelpLoader.Default.TocContainer = _mTOC;
HelpLoader.Default.IndexContainer = _mIndex;
HelpLoader.Default.TopicContainer = _mTopic;
HelpLoader.Default.SearchContainer = _mSearch;
HelpLoader.Default.FavoritesContainer = _mFavorites;
}
您可以在此处找到BackSpin帮助创作工具
http://www.backspinsoftware.com/site/Default.aspx
它从Word文档生成编译帮助。