2011-01-10 2 views
1

마우스 밑에 엔티티가있을 수있는 3D 렌더링이 있습니다. 엔티티에 대한 정보가있는 툴팁이 필요하며 아래 코드를 사용하여이를 수행 할 수 있습니다. 팁은 마우스가 엔터티 위에있을 때 항상 보이고 그렇지 않으면 숨겨집니다. XAML에서 WPF ToolTip 동적 표시/숨기기를 어떻게 얻을 수 있습니까?

// Would like to do this in XAML - it must be possible but not sure how 
string toolTipString = null; 
public void SetToolTipString() 
{ 
    var e = _worldViewModel.MouseOverEntity; 
    string newTip = e == null ? null : e.Entity.Name; 
    if (newTip != toolTipString) 
    { 
     toolTipString = newTip; 
     if (newTip == null) 
     { 
      if (ToolTip != null) 
      { 
       ((ToolTip)ToolTip).IsOpen = false; 
      } 
      ToolTip = null; 
     } 
     else 
     { 
      ToolTip = new ToolTip { Content = toolTipString, IsOpen = true, StaysOpen = true }; 
     } 
    } 
} 

나는이 시도했지만 작동하지 않았다 : XAML에 그것을 달성 할 수있는 방법이

<ToolTip 
    StaysOpen="True" 
    IsOpen="{Binding Path=PlacementTarget.DataContext.IsMouseOverEntity, 
        RelativeSource={RelativeSource Self}}" 
    Content="{Binding Path=PlacementTarget.DataContext.MouseOverEntity.Entity.Name, 
         RelativeSource={RelativeSource Self}}"/> 

있습니까?

+0

당신이 보여줄 수 HTH? –

+0

나는 그 질문을 이해하지 못한다. _worldViewModel.MouseOverEntity는 마우스 아래의 3D 요소를 포함합니다. DataContext가 _worldViewModel로 설정되었습니다. XAML 바인딩은 콘텐츠에 대해서는 작동하지만 IsOpen 적합성에 대해서는 작동하지 않는 것 같습니다. –

+0

바인딩 오류가 발생하고 있습니까? – kevindaub

답변

2

툴팁 클래스는 실제로 Popup class을 사용하여 구현됩니다. Popup 클래스를 사용하여 위의 동일한 작업을 시도해야합니다. 그것은 당신이 그것을 원하는 곳을 보여주기 위해 조금 까다로울 수도 있습니다. (저는 몇 가지 문제를 겪었습니다. 그러나 나는 수업 시간에 충분히 익숙하지 않았습니다.)

Placement Behavior

<Canvas Margin="5" Background="Red" Width="200" Height="150" > 
    <Ellipse Name="ellipse1" 
     Canvas.Top="60" Canvas.Left="50" 
     Height="85" Width="60" 
     Fill="Black"/> 

    <Popup IsOpen="{Binding Path=PlacementTarget.DataContext.IsMouseOverEntity, 
       RelativeSource={RelativeSource Self}}" PlacementTarget="{Binding ElementName=ellipse1}" Content="{Binding Path=PlacementTarget.DataContext.MouseOverEntity.Entity.Name,RelativeSource={RelativeSource Self}}" /> 
</Canvas> 

당신이 당신의 3D 요소에 XAML에서`ToolTip`을 연결하는 방법

+0

'Popup'에는'Content' 속성이 없습니다. –

관련 문제