I don't understand why my MarkupExtension StringFormat does not work with labels but works perfectly with TextBlocks.
Here is a simplified version of my code:
[MarkupExtensionReturnType(typeof (BindingExpression))]
public class Format : MarkupExtension
{
#region Public Properties
public BindingBase Binding { get; set; }
public IValueConverter Converter { get; set; }
public string StringFormat { get; set; }
#endregion
#region Public Methods and Operators
public override object ProvideValue(IServiceProvider serviceProvider)
{
this.Binding.StringFormat = this.StringFormat;
return this.Binding.ProvideValue(serviceProvider);
}
#endregion
}
And the XAML:
<TextBlock Text="{wpfApplication31:Format Binding={Binding Name}, StringFormat=X_{0}}" /> <!-- StringFormat WORKING -->
<Label Content="{wpfApplication31:Format Binding={Binding Name}, StringFormat=X_{0}}" /> <!-- StringFormat NOT WORKING -->
The property 'Name' is a simple string.
I think it's related to the fact that Label is a more complex object than TextBlock but I still don't understand why the StringFormat is not applied.
If anybody can help. Thx