code_junkie

WPF - HeaderStringFormat Doesn't work in Expander

Nov 12th, 2011
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <Expander Header="{Binding Path=MyProperty, StringFormat=Stuff: ({0})}" >
  2. <TextBlock Text="Some Content" />
  3. </Expander>
  4. <Expander HeaderStringFormat="{}Stuff ({0})" Header="{Binding Path=MyProperty}">
  5. <TextBlock Text="Some More Content" />
  6. </Expander>
  7. <Expander HeaderStringFormat="{}Stuff ({0:0})" Header="{Binding Path=MyProperty}">
  8. <TextBlock Text="Even More Content" />
  9. </Expander>
  10.  
  11. <Expander>
  12. <Expander.Header>
  13. <TextBlock Text="{Binding Path=MyProperty, StringFormat=Stuff: ({0})}" />
  14. </Expander.Header>
  15. <Expander.Content>
  16. A Expander with working header
  17. </Expander.Content>
  18. </Expander>
  19.  
  20. String.Format("My string value is: {0}", myValue");
  21.  
  22. public class MyTestClass : IFormattable
  23. {
  24. #region IFormattable Members
  25. public string ToString(string format, IFormatProvider formatProvider)
  26. {
  27. if(format == "n")
  28. {
  29. return "This is my formatted string";
  30. }
  31. else
  32. {
  33. return "this is my non-formatted string";
  34. }
  35. }
  36. #endregion
  37. }
  38.  
  39. <Style TargetType="{x:Type TabItem}">
  40. <Setter Property="HeaderStringFormat" Value="n" />
  41. <Setter Property="ContentStringFormat" Value="" />
  42. </Style>
  43.  
  44. <TabControl>
  45. <TabItem Header="{Binding Content, RelativeSource={RelativeSource Self}}">
  46. <local:MyTestClass />
  47. </TabItem>
  48. </TabControl>
Add Comment
Please, Sign In to add comment