6

ツールチップが開かれようとしているときに、wpf アプリのコントロールのツールチップのテキストをステータス バー内に表示したいと考えています。

もちろん、メイン ウィンドウのすべての子コントロールを再帰的にループして、それらのToolTipOpeningイベントを常に同じメソッドに設定することもできます。しかし、もっと簡単な方法はありますか?

Application.Current.AnyToolTipOpeningイベントみたいなもの?

4

2 に答える 2

9

確かに、これを試してください:

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
        }
    }
于 2009-07-01T10:26:11.663 に答える
1

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));
于 2009-07-02T08:47:09.930 に答える