elp
elp

Reputation: 8131

Bind text and variable value togheter

How can use this text value?

Text="My custom text: {Binding MyData}"

In this code?

<TextBlock x:Name="lbl_data" Foreground="Black" TextWrapping="Wrap" 
 Margin="50,39,130,0" FontSize="13.333" FontFamily="Segoe WP Light" 
 VerticalAlignment="Top" Height="26" 
 Text="My custom text: {Binding MyData}" 
/>

thanks.

Upvotes: 1

Views: 487

Answers (3)

Haini
Haini

Reputation: 964

The question is quite old, but since I was looking for a similar solution I will post my answer too. I didn't want to use a converter and I'm using .NET 4.5 with WPF - so it doesn't really apply to the original question. <Run></Run> did work for me as mentioned in the question above

<TextBlock x:Name="lbl_data" Foreground="Black" TextWrapping="Wrap" 
 Margin="50,39,130,0" FontSize="13.333" FontFamily="Segoe WP Light" 
 VerticalAlignment="Top" Height="26"/>
    <Run Text"My custom text: "/>     
    <Run Text="{Binding Path=MyData}"/>
</TextBlock>

Upvotes: 0

Eyjafjallajokull
Eyjafjallajokull

Reputation: 168

Use run:

<TextBlock x:Name="lbl_data" Foreground="Black" TextWrapping="Wrap" 
       Margin="50,39,130,0" FontSize="13.333" FontFamily="Segoe WP Light" 
       VerticalAlignment="Top" Height="26" 
       ext="My custom text: {Binding MyData}">
<TextBlock.Text>
     <Run Text="My custom text:" />
     <Run Text="{Binding MyData}" />
</TextBlock.Text>

Upvotes: 1

kanchirk
kanchirk

Reputation: 912

You can write a Converter and pass in the Parameter MyData

If it was Silverlight 4.0 you can inherently use Value Converter like this

<Button Content={Binding MyData, StringFormat='My Custom Text \{0\}'}/>

Also Refer Question : Binding with StringFormat on Windows Phone 7?

Upvotes: 0

Related Questions