Search code examples
wpfxamlbindingmarkup-extensions

How is a markup extension method applied to a binding value in XAML?


I have a localization markup extension method for strings, which I can apply in this way:

<TextBlock Text="{l:Translate 'My string'}" />

How can I apply this markup extension method to the result of a binding? I.e. something like that:

<TextBlock Text="{l:Translate '{Binding Path=myStringParameter}'}" />

Solution

  • With a markup extention just do this:

    {l:Translate {Binding Path=myStringParameter}}
    

    The XAML parser will handle the inner markup extention itself. Like in classical WPF: {StaticResource {x:Type Button}}