I am able to bind a static class property to a MenuItem header, but I cannot determine how to include a StringFormat so that I can display hard-coded text in addition to the property.
Is this possible?
Currently: (Displays "SQLSERVER1")
Header="{x:Static settings:Settings.CurrentServer}"
Desired: (Display "Connection: SQLSERVER1")
Header="{Binding Source={x:Static Settings:Settings.CurrentServer},StringFormat='Connection: {0}'}"
When I try the 'Desired' line in the XAML the StringFormat is ignored entirely. What am I doing wrong?
MenuItem provides a HeaderStringFormat property that you should use:
<MenuItem Header="{Binding Source={x:Static Settings:Settings.CurrentServer}}"
          HeaderStringFormat="Connection: {0}" />
Actually, that property is part of HeaderedItemsControl, which MenuItem happens to extend.
The StringFormat property is just ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With