Christian Studer
Christian Studer

Reputation: 25597

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}'}" />

Upvotes: 4

Views: 1549

Answers (2)

C&#233;dric Bignon
C&#233;dric Bignon

Reputation: 13022

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}}

Upvotes: 1

Geerten
Geerten

Reputation: 1057

I believe it is not possible the way you do it, but you can rewrite its as follows:

 <TextBlock>
     <TextBlock.Text>
        <l:Translate>
           <Binding Path="myStringParameter" />
        </l:Translate>
     </TextBlock.Text>
 </TextBlock>

Upvotes: 1

Related Questions