共用方式為


ToolTipService.ToolTipOpeningEvent 欄位

定義

識別由使用 ToolTipOpening 服務以顯示工具提示之物件公開 ToolTipService 事件。

public: static initonly System::Windows::RoutedEvent ^ ToolTipOpeningEvent;
public static readonly System.Windows.RoutedEvent ToolTipOpeningEvent;
 staticval mutable ToolTipOpeningEvent : System.Windows.RoutedEvent
Public Shared ReadOnly ToolTipOpeningEvent As RoutedEvent 

欄位值

範例

下列範例示範如何設定事件的事件處理常式 FrameworkElement.ToolTipOpening 。 在此情況下,事件處理常式實際上是 針對 FrameworkElement.ToolTipOpening ,因為 Ellipse 附加處理常式所在的 是 的 FrameworkElement 衍生類別。

ellipse2.AddHandler(ToolTipService.ToolTipOpeningEvent,
    new RoutedEventHandler(whenToolTipOpens));
ellipse2.AddHandler(ToolTipService.ToolTipClosingEvent,
    new RoutedEventHandler(whenToolTipCloses));
ellipse2.AddHandler(ToolTipService.ToolTipOpeningEvent, New RoutedEventHandler(AddressOf whenToolTipOpens))
ellipse2.AddHandler(ToolTipService.ToolTipClosingEvent, New RoutedEventHandler(AddressOf whenToolTipCloses))

void whenToolTipOpens(object sender, RoutedEventArgs e)
{
    Ellipse ell = new Ellipse();
    if (sender.GetType().FullName.Equals("System.Windows.Shapes.Ellipse"))
    {
        ell = (Ellipse)sender;
        ell.Fill = Brushes.Blue;
    }
    else if (sender.GetType().FullName.Equals(
                             "System.Windows.Controls.ToolTip"))
    {
        ToolTip t = (ToolTip)sender;
        Popup p = (Popup)t.Parent;
        ell = (Ellipse)p.PlacementTarget;
        ell.Fill = Brushes.Blue;
    }
}

void whenToolTipCloses(object sender, RoutedEventArgs e)
{
    Ellipse ell = new Ellipse();
    if (sender.GetType().FullName.Equals(
                      "System.Windows.Shapes.Ellipse"))
    {
        ell = (Ellipse)sender;
        ell.Fill = Brushes.Gray;
    }
    else if (sender.GetType().FullName.Equals(
                           "System.Windows.Controls.ToolTip"))
    {
        ToolTip t = (ToolTip)sender;
        Popup p = (Popup)t.Parent;
        ell = (Ellipse)p.PlacementTarget;
        ell.Fill = Brushes.Gray;
    }
}

Private Sub whenToolTipOpens(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim ell As New Ellipse()
    If sender.GetType().FullName.Equals("System.Windows.Shapes.Ellipse") Then
        ell = CType(sender, Ellipse)
        ell.Fill = Brushes.Blue
    ElseIf sender.GetType().FullName.Equals("System.Windows.Controls.ToolTip") Then
        Dim t As ToolTip = CType(sender, ToolTip)
        Dim p As Popup = CType(t.Parent, Popup)
        ell = CType(p.PlacementTarget, Ellipse)
        ell.Fill = Brushes.Blue
    End If
End Sub

Private Sub whenToolTipCloses(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim ell As New Ellipse()
    If sender.GetType().FullName.Equals("System.Windows.Shapes.Ellipse") Then
        ell = CType(sender, Ellipse)
        ell.Fill = Brushes.Gray
    ElseIf sender.GetType().FullName.Equals("System.Windows.Controls.ToolTip") Then
        Dim t As ToolTip = CType(sender, ToolTip)
        Dim p As Popup = CType(t.Parent, Popup)
        ell = CType(p.PlacementTarget, Ellipse)
        ell.Fill = Brushes.Gray
    End If
End Sub

備註

事件 ToolTipOpening 會在工具提示開啟之前立即發生。 如果未定義工具提示,或工具提示內容設定為 Null,則不會發生此事件。

此欄位會針對使用此服務之 ToolTipOpening 類別註冊事件的行為。 和 FrameworkElementFrameworkContentElement 類別都會透過 Common Language Runtime (CLR) 存取子 FrameworkElement.ToolTipOpeningFrameworkContentElement.ToolTipOpening 來實 ToolTipService 作 和 公開此事件。

如果您將工具提示指定為 ToolTip 物件, Opened 當工具提示開啟時也會引發 事件。

適用於

另請參閱