C# WPF,动态工具提示,MouseLeftButtonUp 不触发

有代码


ToolTip tt;


private void Grid_Loaded(object sender, RoutedEventArgs e)

{


    Label l = new Label();

    l.Content = "ToolTip";

    l.MouseLeftButtonUp += l_MouseLeftButtonUp;

    Grid.SetColumn(l, 0);

    Grid.SetRow(l, 0);

    grid.Children.Add(l);


    tt = new ToolTip();

    tt.StaysOpen = true;

    tt.MouseLeftButtonUp += tt_MouseLeftButtonUp;

    tt.Content = "12345";


}


void l_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

{


    tt.IsOpen = true;


}


void tt_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

{


    throw new NotImplementedException();


}

当鼠标单击标签工具提示时显示。然后,如果工具提示鼠标单击 tt_MouseLeftButtonUp 事件永远不会触发。为什么?


有只小跳蛙
浏览 759回答 2
2回答

Helenr

谢谢。随着弹出它的工作正常System.Windows.Controls.Primitives.Popup popup;...StackPanel sp = new StackPanel();sp.Margin = new Thickness(10, 10, 10, 10);Label l1 = new Label();l1.Content = "Test label 1";l1.Tag = 1;l1.MouseLeftButtonUp += l1_MouseLeftButtonUp;sp.Children.Add(l1);Border b = new Border();b.BorderBrush = System.Windows.Media.Brushes.Black;b.Background = System.Windows.Media.Brushes.White;b.BorderThickness = new Thickness(1);b.CornerRadius = new CornerRadius(10);b.Child = sp;popup = new System.Windows.Controls.Primitives.Popup();popup.Child = b;popup.AllowsTransparency = true;popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;popup.MouseLeave += popup_MouseLeave;...void popup_MouseLeave(object sender, MouseEventArgs e){popup.IsOpen = false;}

肥皂起泡泡

ToolTips 窗口无法接受焦点,请使用 Popup 控件,您可以使用 Click On it您创建的工具提示保持打开状态,直到用户单击其他位置。但是,ToolTipService.ShowDuration 属性给出工具提示自动消失前的时间(默认为 5 秒)或用户将鼠标移开时的时间。如果您想创建一个类似工具提示的窗口并无限期地保持打开状态,最简单的方法是使用 Popup 控件。
打开App,查看更多内容
随时随地看视频慕课网APP