I have a WPF Expander in my project. I have applied styles to the expander to change the header colors and whatnot. After doing so, my data is still bound to the Header's content area, but it just binds the raw data and not the formatting I have specified. See the examples below.
<Style x:Key="ValkyrieStyleExpander" TargetType="{x:Type Expander}">
<!-- Ommiting property setters for brevity -->
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" FontWeight="Bold"
Foreground="White" VerticalAlignment="Center" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
And here is the actual declaration with the appropriate binding syntax
<Expander Style="{StaticResource ValkyrieStyleExpander}"
Margin="10,10,0,0"
Width="670"
Header="{Binding PolicyNumber, StringFormat=Policy {0}}">
</Expander>
We I run the app, the header should display "Policy 123456", and before I restyled the expander it did so. But now when I run the app, the header just shows "123456". I am still kind of a babe-in-the-woods when it comes to databinding, so I am not sure really what I need to do to get the new style to show the correct data. Hopefully the answer isn't to add it to the ValkyrieStyleExpender's Header Template style, as that would defeat the purpose of having a style (Not all expanders in the project are for displaying a particular policy)
StringFormat
never should work in a binding for theExpander.Header
property)?StringFormat
works only for properties that have typestring
. – user128300PolicyNumber
is of typestring
? – Rohit Vats