简体   繁体   中英

Add text to TextBlock Text property when it's binded

I have a TextBlock where its Text property is binded with another property that rappresents a value:

<TextBlock Text="{Binding Path=Count}" FontWeight="Bold" />

So, if (for example) Count is 4 , I'll see in my TextBlock the number 4 .

Now, what I have to do if I want to add some text before and after the number 4 (for example I'd like to see that number in square brackets [4] )?

Thanks.

您可以使用stringformat

<TextBlock Text="{Binding Path=Count, StringFormat={}[{0}]}" FontWeight="Bold" />

You can also try with - Based on MultiBinding

<TextBlock.Text>
    <MultiBinding StringFormat=" {0}{1}{2}">
        <Binding Path="Prefixe"/>
        <Binding Path="Count"/>
        <Binding Path="Suffixe"/> 
    </MultiBinding>
</TextBlock.Text>

Nota : Set Suffixe and Prefix

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM