Page 1 of 1

Unable to use StringFormat in a tab item header?

Posted: 09 Jan 2020, 04:02
by jswigart
Any reason why I can't get this to work?

It just shows the count, not the formatted string.
<TabItem Header="{Binding Resources.Textures.Count, StringFormat=Textures {0:D}}">

Re: Unable to use StringFormat in a tab item header?

Posted: 09 Jan 2020, 10:39
by sfernandez
StringFormat only applies when target property of the binding is of type String, and in this case TabItem.Header is of type object.

But you can use a TextBlock as Header or as part of the HeaderTemplate, and specify the string format there:
<TabItem>
  <TabItem.Header>
    <TextBlock Text="{Binding Resources.Textures.Count, StringFormat=Textures {0:D}}"/>
  </TabItem.Header>
</TabItem>