Search code examples
wpfstringxamlmultibindingstring-formatting

How to add conditions in a Multibinding string block? (WPF)


I am trying to format the title of my Application but it seems some basic WPF details escape me. Here is my code:

<Window.Title>
   <MultiBinding StringFormat="{}{0} - {1}">
      <Binding Path="Shell.Workbench.Title" />
      <Binding Path="Shell.Workbench.CurrentFileName" />
   </MultiBinding>
</Window.Title>

The problem is that my second field can sometimes be en empty string. If that is the case how can I hide the dash between them?

Example: If both strings exist, I have a title like this "Title - CurrentFileName". If second string is empty, I have "Title -" and I want to have just "Title".

Thank you


Solution

  • *this is an answer i've edited my commant
    you can use a converter http://msdn.microsoft.com/en-us/library/system.windows.data.multibinding.converter.aspx and in it do the text manipulations