wpf中利用代码完成自定义tooltip

没啥可说的,简单的代码如下:

 1 using  System;
 2 using  System.Collections.Generic;
 3 using  System.Linq;
 4 using  System.Text;
 5 using  System.Windows;
 6 using  System.Windows.Controls;
 7 using  System.Windows.Data;
 8 using  System.Windows.Documents;
 9 using  System.Windows.Input;
10 using  System.Windows.Media;
11 using  System.Windows.Media.Imaging;
12 using  System.Windows.Navigation;
13 using  System.Windows.Shapes;
14
15 namespace  tooltip
16 ExpandedBlockStart.gifContractedBlock.gif {
17ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
18    /// Window1.xaml 的交互逻辑
19    /// </summary>

20    public partial class Window1 : Window
21ExpandedSubBlockStart.gifContractedSubBlock.gif    {
22        public Window1()
23ExpandedSubBlockStart.gifContractedSubBlock.gif        {
24            InitializeComponent();
25            button1.ToolTip = GetToolTip("11""22");
26        }

27        private ToolTip GetToolTip(string name, string remark)
28ExpandedSubBlockStart.gifContractedSubBlock.gif        {
29
30
31
32            StackPanel sp = new StackPanel();
33
34            Label lb = new Label();
35            lb.FontWeight = FontWeights.Bold;
36            lb.Background = Brushes.Blue;
37            lb.Foreground = Brushes.White;
38            lb.Content = name + "检测结果";
39            sp.Children.Add(lb);
40
41            TextBlock tb = new TextBlock();
42            tb.Padding = new Thickness(10);
43            tb.TextWrapping = TextWrapping.WrapWithOverflow;
44            tb.Width = 200;
45            tb.Text = name + "\r" + remark;
46            sp.Children.Add(tb);
47
48            Line ln = new Line();
49            ln.Stroke = Brushes.Black;
50            ln.StrokeThickness = 1;
51            ln.X2 = 200;
52            sp.Children.Add(ln);
53
54            StackPanel sp2 = new StackPanel();
55            sp2.Orientation = Orientation.Horizontal;
56
57            //-------------------sp2中增加一张图片----------------------
58
59            Image myImage3 = new Image();
60            BitmapImage bi3 = new BitmapImage();
61            bi3.BeginInit();
62            bi3.UriSource = new Uri("images/help.jpg", UriKind.Relative);
63            bi3.EndInit();
64            myImage3.Stretch = Stretch.Fill;
65            myImage3.Source = bi3;
66            sp2.Children.Add(myImage3);
67
68            //-----------------------------------------------------------
69
70            Label lb2 = new Label();
71            lb2.FontWeight = FontWeights.Bold;
72            lb2.Content = "右键菜单显示路由信息";
73            sp2.Children.Add(lb2);
74
75            sp.Children.Add(sp2);
76
77            ToolTip ttp = new ToolTip();
78
79            ttp.Content = sp;
80            
81
82            return (ttp);
83        }

84    }

85}

86

 

转载于:https://www.cnblogs.com/luyingxue/archive/2008/08/30/1279934.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值