Bohrend
Bohrend

Reputation: 1497

Windows Phone 8 xaml textblock binding format

I would like to format a textblock which is bound to a value, to show "R" before the actual value, is this possible, cause I cannot directly change the value?

Thank you

<ListBox x:Name="lstbundleListbox"
         Foreground="White"
         Height="320"
         HorizontalAlignment="Center">
  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="HorizontalContentAlignment"
              Value="Center" />
    </Style>
  </ListBox.ItemContainerStyle>
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBlock Text="{Binding name}"
                   TextWrapping="Wrap"
                   HorizontalAlignment="Center" />

        <TextBlock Text="{Binding cost}"
                   TextWrapping="Wrap"
                   HorizontalAlignment="Center" />
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel Orientation="Vertical" />
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ListBox>

So I basically want the textblock to show R(cost)

Upvotes: 1

Views: 3181

Answers (2)

Sandeep Chauhan
Sandeep Chauhan

Reputation: 1313

i think this can be done by

  <StackPanel Orientation Horizontal>
       <TextBlock Text="R(" />
       <TextBlock Text="{Binding cost}"/>
       <TextBlock Text=")" />
   </StackPanel>

distance between them can be set by setting padding of the textblocks...

Upvotes: 0

AKD
AKD

Reputation: 3966

use Run

<TextBlock>
    <Run Text="R" />
    <Run Text="{Binding cost}" />
</TextBlock>

or use StringFormat

<TextBlock Text="{Binding cost, StringFormat=R{0}}" />

Upvotes: 8

Related Questions