有代码
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事件,则永远不会触发。为什么?
发布于 2018-09-10 16:59:06
谢谢。使用popup可以很好地工作
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;
}发布于 2018-09-10 00:27:23
ToolTips窗口不能接受焦点,请使用Popup控件,您可以使用单击它
您可以创建保持打开状态的工具提示,直到用户单击其他位置。但是,ToolTipService.ShowDuration属性提供了工具提示自动消失(默认为5秒)或用户将鼠标移开之前的时间。如果您想要创建一个类似工具提示的窗口,该窗口将无限期地打开,最简单的方法是使用Popup控件。
https://stackoverflow.com/questions/52246238
复制相似问题