2

FYI - I am a C# / WPF newbie.

I have been tasked with incorporating context sensitive help via the F1 key in an existing C# WPF application.

We do not want to go the route of using chm (windows html help) but instead we would like to open a particular page on a wiki that can be more easily maintained and updated.

All of the examples I have been able to find demonstrate how to use chm files. Furthermore, they require adding the help provider to each element which could prove very time consuming.

Instead I have been kicking around the idea of trying to determine which control (or at least it's container or window) has focus in order to determine the page to open. I will then match its name to a url in our database. For this I tried recursively looping over the FrameworkElement objects returned from the VisualTreeHelper, but it returns a staggering number of elements and strikes me as an inefficient way of trying to find what I want.

Does anyone have suggestions on what my best approach might be? Can you direct me to samples of opening a browser and passing a URL to it from within a WPF app based on a key press?

Any help is appreciated. I have been spinning my wheels on this for too long already!

LALCB

  • related and kind of answers the question, although you will have to extend it to cater for context: http://stackoverflow.com/a/6152775/492 – CAD bloke Jan 13 '15 at 09:55

1 Answers1

1

If you have a large number of controls, this could be cumbersome. But a start may be to handle PreviewKeyDown or PreviewKeyUp for each control and filter on F1. Then put this in the handler:

System.Diagnostics.Process.Start(@"[the url]");

[the url] is specific to the control, so you will not need the lookup table because you know which event handler you are in.

You could also go the route of one event handler assigned to all the PreviewKeyDown or PreviewKeyUp events, and then use your database lookup based off the sender object information.

Josh
  • 2,955
  • 1
  • 19
  • 28