2016-07-26 8 views

답변

2

내가 이런 걸 사용합니다 :

class ToolTipHelper 
{ 
    private readonly ToolTip _toolTip; 
    private readonly Timer _timer; 

    /// <summary> 
    /// Creates an instance 
    /// </summary> 
    public ToolTipHelper() 
    { 
     _toolTip = new ToolTip(); 
     _timer = new Timer { AutoReset = false}; 
     _timer.Elapsed += ShowToolTip; 
    } 

    /// <summary> 
    /// Gets or sets the text for the tooltip. 
    /// </summary> 
    public object ToolTipContent { get{ return _toolTip.Content; } set{ _toolTip.Content = value; } } 

    /// <summary> 
    /// To be called when the mouse enters the ui area. 
    /// </summary> 
    public void OnMouseEnter(object sender, MouseEventArgs e) 
    { 
     _timer.Interval = ToolTipService.GetInitialShowDelay(Application.Current.MainWindow); 
     _timer.Start(); 
    } 

    private void ShowToolTip(object sender, ElapsedEventArgs e) 
    { 
     _timer.Stop(); 
     if (_toolTip != null) 
      _toolTip.Dispatcher.Invoke(new Action(() => { _toolTip.IsOpen = true; })); 
    } 

    /// <summary> 
    /// To be called when the mouse leaves the ui area. 
    /// </summary> 
    public void OnMouseLeave(object sender, MouseEventArgs e) 
    { 
     _timer.Stop(); 
     if (_toolTip != null) 
      _toolTip.IsOpen = false; 
    } 

는 다음과 같이 Teapot을 수정

class Teapot 
{ 
    private readonly _tooltipHelper = new ToolTipHelper{ ToolTipContent = "MyToolTip" }; // keep the ToolTipHelper during the life of your Teapot but replace the Content whenever you want 

    private ModelUIElement3D _uiModel; // this has to be created and have its Model set to the suitable GeometryModel3D. You may want to replace an existing ModelVisual3D by this. 

    public Teapot(/*...*/) 
    { 
     _uiModel.MouseEnter += tooltipHelper.OnMouseEnter; 
     _uiModel.MouseLeave += tooltipHelper.OnMouseLeave; 

     //... 
    } 

    // ... 
} 

의 내용을 정의하는이를 수정하기 어려울하지 말아야을 원하는 경우 Xaml의 툴팁.

+0

흥미 롭다면, 나는 그것이 그렇게 사소한 작업이기 때문에 훨씬 더 단순해야한다고 생각했다. 솔루션을 주셔서 감사합니다, 그것을 밖으로 시도합니다 :) – HuyNA

+0

당신이 간단한 방법을 찾으면, 여기에 우리에게 알려주십시오. – wkl