How to convert this code-based WPF tooltip to Silverlight?

雨燕双飞 提交于 2019-12-12 13:19:52

问题


The following ToolTip code works in WPF.

I'm trying to get it to work in Silverlight.

But it gives me these errors:

TextBlock does not contain a definition for ToolTip.
Cursors does not contain a definition for Help.
ToolTipService does not contain a definition for SetInitialShowDelay.

How can I get this to work in 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:


Tooltips are added to Silverlight controls using an attached property provided by the ToolTipService. There is no SetInitialShowDelay in Silverlight's version nor is there a Help cursor on the Cursors type.

    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);
    }


来源:https://stackoverflow.com/questions/2469339/how-to-convert-this-code-based-wpf-tooltip-to-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!