【问题标题】:Windows Phone 8 xaml textblock binding formatWindows Phone 8 xaml 文本块绑定格式
【发布时间】:2013-10-22 03:16:25
【问题描述】:

我想格式化一个绑定到值的文本块,在实际值之前显示“R”,这可能吗,因为我不能直接更改值?

谢谢

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

所以我基本上希望文本块显示 R(cost)

【问题讨论】:

    标签: xaml windows-phone-8 datatemplate


    【解决方案1】:

    使用Run

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

    或使用StringFormat

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

    【讨论】:

      【解决方案2】:

      我认为这可以通过

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

      它们之间的距离可以通过设置文本块的填充来设置...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-11
        • 1970-01-01
        • 2014-01-15
        • 2013-12-30
        • 2014-03-30
        • 2013-06-08
        • 1970-01-01
        相关资源
        最近更新 更多