如何将帮助附加到VS 2008内置的WPF应用程序
我的应用程序有一个chm,我想在用户按F1键时将其附加到我的应用程序中。打开项目的附加帮助。我不知道WPF中有任何内置的支持来显示chm文件。我要做的是添加一个InputSignature以将F1击键连接到Application.Help命令,并在Windows CommandBindings中为Application.Help命令添加一个处理程序。下面是一个示例代码:如何将帮助附加到VS 2008内置的WPF应用程序,wpf,Wpf,我的应用程序有一个chm,我想在用户按F1键时将其附加到我的应用程序中。打开项目的附加帮助。我不知道WPF中有任何内置的支持来显示chm文件。我要做的是添加一个InputSignature以将F1击键连接到Application.Help命令,并在Windows CommandBindings中为Application.Help命令添加一个处理程序。下面是一个示例代码: <Window x:Class="WpfTestApp.MainWindow" xmlns="http://sc
<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>
基于这种方法,我做了以下工作,这样我就可以利用我拥有的通过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);
}
}
确定,将源viewmodel上的命令绑定到此窗口
然后在此窗口上为命令创建一个处理程序(也许可以以某种方式内联)
现在,您可以在任何地方调用OnlineHelpViewModel上的单个help命令,它也可以任意复杂。请注意,DP HelpContextGuid是传递的-由命令决定如何处理它,但relayCommand需要一个参数
命令本身看起来像(在源Viewmodel上)
您可以在此处找到BackSpin帮助创作工具
它从Word文档生成编译后的帮助。这就是我要问的问题,如何做到这一点?
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));
private void HelpCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
this.HelpCommand.Execute(HelpContextGuid);
}
...
ShowApplicationHelpCommand = new RelayCommand<string>(
(h) => { ShowApplicationHelp(h); },
(h) => CanShowApplicationHelpCommand);
...
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;
}