Microsoft Developer Network >
Página Inicial dos Fóruns
>
Windows Presentation Foundation (WPF)
>
Context Sensitive Help In WPF
Context Sensitive Help In WPF
- Hi all, I am working with implementing a help system for my WPF application. I have applied the following technique:
http://peteohanlon.wordpress.com/2009/05/01/easy-help-with-wpf/
It seems as though when applied, pressing F1 will sends the selected , or focused element as the sender
The one thing that I would like to do different is to use the item that my mouse is over as the sender, without having to click on it.
Is this possible?
Thanks in advance!
Respostas
- Hi,
if you are using Pete's code just as it is, replace e.originalsource with Mouse.DirectlyOver. In addition to that, you will have to make sure that all these events are only handled through the page or window, not through the individual frameworkelements, so I suggest that you don't use a ClassCommandBinding, but add a normal commandbinding for the Help command to the page's or window's CommandBindings collection.
You can do that simply and elegantly during the DependencyPropertyChanged handler of the Help.Filename attached property.
If you have complex controls, the Help.Keyword you need to display the help topic may not even be defined on the control the mouse is over, but on one of its parents, so you might want to walk up the visual tree in order to find it, just as Pete does for the filename in his FindFilename function.
However, if you do that, of course the original method of displaying help for the focused element will stop working, so if you still want that, you might define different commands and keyboard shortcuts for the two cases.
By the way, thanks for pointing out Pete's article here, this is 1A WPFGlue...- Marcado como RespostaRockwellDesign77 quarta-feira, 4 de novembro de 2009 17:16
Todas as Respostas
- Hi Rockwell,
You can use the Mouse.DirectlyOver property to get the element that the mouse is currently over in the Executed event handler.
private void Help_Executed(object sender, ExecutedRoutedEventArgs e)
{
Console.WriteLine("Mouse directly over: " + Mouse.DirectlyOver .ToString());
..... other code here.....
}
However, if you want to show the help information when the mouse over an element, it's better to use Tooltips .
If anything is unclear, please feel free to let me know.
Best Regards,
Zhi-Xin Ye
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!- Sugerido como RespostaRahul P Nath quarta-feira, 4 de novembro de 2009 5:04
- Não Sugerido como RespostaRockwellDesign77 quarta-feira, 4 de novembro de 2009 16:18
- Hi Zhi-Xin Ye, thanks for the response. For my situation, i already have some tool tip type of roll overs, but what I am looking for is to display some in depth info in the help.chm file when the user has their mouse over the element and hits F1. The way I have it working now, if you click on the element, lets say a text box, once it has focus and you hit F1, it will bring up the associated topic in the help.chm. What I want to be able to do is detect the text box as my sender when I perform a mouse over, rather than clicking it and setting its focus. In my application, the controls that I am attempting to apply this to are not as simple as a text box, and have a great deal of info related to them, hence the need to open the chm file. I tried using your suggestion, and am able to read in the element that has the Mouse.DirectlyOver property, but how do I set the element that has this property to be the sender? Thanks for your previous help and any additional info.
- Hi,
if you are using Pete's code just as it is, replace e.originalsource with Mouse.DirectlyOver. In addition to that, you will have to make sure that all these events are only handled through the page or window, not through the individual frameworkelements, so I suggest that you don't use a ClassCommandBinding, but add a normal commandbinding for the Help command to the page's or window's CommandBindings collection.
You can do that simply and elegantly during the DependencyPropertyChanged handler of the Help.Filename attached property.
If you have complex controls, the Help.Keyword you need to display the help topic may not even be defined on the control the mouse is over, but on one of its parents, so you might want to walk up the visual tree in order to find it, just as Pete does for the filename in his FindFilename function.
However, if you do that, of course the original method of displaying help for the focused element will stop working, so if you still want that, you might define different commands and keyboard shortcuts for the two cases.
By the way, thanks for pointing out Pete's article here, this is 1A WPFGlue...- Marcado como RespostaRockwellDesign77 quarta-feira, 4 de novembro de 2009 17:16
- Sounds great, thanks for the response, but where do you see e.original source?
- Marcado como RespostaRockwellDesign77 quarta-feira, 4 de novembro de 2009 17:16
- Não Marcado como RespostaRockwellDesign77 quarta-feira, 4 de novembro de 2009 17:16
- dummy me, i found it, args.originalsource, got it. thanks a lot!

