Вопрос

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

Это было полезно?

Решение

*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

Другие советы

Hmm, ok it's just an alternative, because you are asking for a solutions with MultiBinding but I would create an additional property (for joining the strings) in the ViewModel, which behaves that way, and bind it to the view.

Every other method like ValueConverters wouldn't be worth the effort.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top