Question

I'm assuming the reason this isn't working is because my triggers are checking for an empty string or null, yet what I really have is a textblock with a Text property that is empty (or null). Does anyone know how I can easily modify my triggers to make this happen? I've messed around for a half hour trying different ways of binding/triggers/datatriggers, with no luck.

<ListView.ItemContainerStyle>
   <Style TargetType="ListViewItem">

      <Setter Property="ToolTip">
         <Setter.Value>
            <!--Can't be directly in tool tip, cuz tool tip is object. StringFormat will only work with string-->
            <TextBlock>
               <TextBlock.Text>
                  <MultiBinding StringFormat="{}ID: {0}&#x0a;X: {1}&#x0a;Y: {2}">
                     <Binding Path="MyClass.Id"/>
                     <Binding Path="MyClass.x"/>
                     <Binding Path="MyClass.y"/>
                  </MultiBinding>
               </TextBlock.Text>
            </TextBlock>
         </Setter.Value>
      </Setter>

      <Style.Triggers>
         <Trigger Property="ToolTip.Content"  Value="{x:Static System:String.Empty}">
            <Setter Property="ToolTip.Visibility" Value="Collapsed" />
         </Trigger>
         <Trigger Property="ToolTip.Content" Value="{x:Null}">
            <Setter Property="ToolTip.Visibility" Value="Collapsed" />
         </Trigger>
     </Style.Triggers>

   </Style>
</ListView.ItemContainerStyle>
Was it helpful?

Solution

So I actually kept the style above exactly the same. It seems like the problem was that when my "MyClass" object is null, an empty tool tip is displayed.

But when "MyClass" is null, I really want the tool tip to stop showing.

I get around this with the following datatrigger:

  <DataTrigger Binding="{Binding Path=MyClass}" Value="{x:Null}">
     <Setter Property="ToolTip" Value="{x:Null}" />
  </DataTrigger>

The other triggers I had in my original post are no longer needed. By setting ToolTip to null in the snippet above, the tool tip will automatically not show.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top