如何将基于代码的 WPF 工具提示转换为 Silverlight?

3
以下工具提示代码适用于WPF。我正在尝试让它在Silverlight中起作用,但它给了我这些错误:
TextBlock does not contain a definition for ToolTip.
Cursors does not contain a definition for Help.
ToolTipService does not contain a definition for SetInitialShowDelay.

如何在Silverlight中使此功能起作用?

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace TestHover29282
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            AddCustomer("Jim Smith");
            AddCustomer("Joe Jones");
            AddCustomer("Angie Jones");
            AddCustomer("Josh Smith");
        }

        void AddCustomer(string name)
        {
            TextBlock tb = new TextBlock();
            tb.Text = name;
            ToolTip tt = new ToolTip();
            tt.Content = "This is some info on " + name + ".";
            tb.ToolTip = tt;
            tt.Cursor = Cursors.Help;
            ToolTipService.SetInitialShowDelay(tb, 0);

            MainStackPanel.Children.Add(tb);
        }
    }
}
1个回答

4

使用ToolTipService提供的附加属性,可以将工具提示添加到Silverlight控件中。在Silverlight版本中没有SetInitialShowDelay,也没有Cursors类型上的Help光标。

    void AddCustomer(string name)
    {
        TextBlock tb = new TextBlock();
        tb.Text = name;
        ToolTip tt = new ToolTip();
        tt.Content = "This is some info on " + name + ".";
        ToolTipService.SetToolTip(tb, tt);

        MainStackPanel.Children.Add(tb);
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接