Tooltip: Multibinding failed because it has no valid converter

Maybe you forgot it everytime ToolTip is more than a simple text.

Here is an example of a simple TextBlock control:

  <TextBlock Text="{Binding Path=Person.NameSurname}" 
        ToolTip="{Binding Path=Persona.LocalAddress}" />

What would you do if you want have a reacher ToolTip…person’s mobile phone number too?

Well you can’t simply have something like this 😦

  <TextBlock Text="{Binding Path=Person.NameSurname}">
      <TextBlock.ToolTip>
        <Multibinding StringFormat="{}{0} - m. {1}">
              <Binding Path="Person.LocalAddress" />
              <Binding Path="Person.Mobile" />
        </Multibinding>    
      </TextBlock.ToolTip>  
  </TextBlock>

You get the error “Multibinding failed because it has no valid converter”.
Why?
Compare Text vs ToolTip MSDN page in TextBlock control …
you got it ?!?
Text is a String, ToolTip is an object, straight from FrameworkElement!

So you can define a style for it, a template, or something simpler … like this 😉

  <TextBlock Text="{Binding Path=Person.NameSurname}">
      <TextBlock.ToolTip>
          <TextBlock>
              <TextBlock.Text>
                  <Multibinding StringFormat="{}{0} - m. {1}">
                      <Binding Path="Person.LocalAddress" />
                      <Binding Path="Person.Mobile" />
                  </Multibinding>    
              </TextBlock.ToolTip>  
          </TextBlock>
      </TextBlock.ToolTip>
  </TextBlock>

Easier, ain’t it? 🙂

Technorati Tags: ,,,.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: