ツールチップが開かれようとしているときに、wpf アプリのコントロールのツールチップのテキストをステータス バー内に表示したいと考えています。
もちろん、メイン ウィンドウのすべての子コントロールを再帰的にループして、それらのToolTipOpening
イベントを常に同じメソッドに設定することもできます。しかし、もっと簡単な方法はありますか?
Application.Current.AnyToolTipOpening
イベントみたいなもの?
確かに、これを試してください:
EventManager.RegisterClassHandler(typeof(FrameworkElement), FrameworkElement.ToolTipOpeningEvent, new ToolTipEventHandler(ToolTipHandler));
これは、FrameworkElementから派生するすべてのクラスのハンドラーを登録します。
ハンドラーメソッドは次のようになります。
private void ToolTipHandler(object sender, ToolTipEventArgs e) {
// To stop the tooltip from appearing, mark the event as handled
e.Handled = true;
FrameworkElement source = e.Source as FrameworkElement;
if (source != null) {
MessageBox.Show(source.ToolTip.ToString()); // or whatever you like
}
}
thanks , that worked. Additionally,to make the statusbar text disappear when the mouse leaves the control with the tooltip :
EventManager.RegisterClassHandler(typeof(FrameworkElement),
MouseLeaveEvent, new MouseEventHandler(ClearText));