如何在JSON中使文本粗体并将其绑定到Windows Phone

时间:2014-08-27 01:24:41

标签: json windows-phone-8

我有以下JSON文件,我绑定到Windows Phone文本块

{"Groups":[
  {
    "UniqueId": "Cat-1",
    "Title": "Inspirational",
    "ImagePath": "Assets/DarkGray.png",
    "Items":
    [
      {
        "UniqueId": "11",
        "Title": "Item Title: 1",
        "ImagePath": "Assets/LightGray.png",
        "Description" : "The best and most beautiful things in the world...",
        "Content" : "The best and most beautiful things in the world",
        "Author" : "Helen Keller"
      }
    ]
  }
]
}

以上文件内容数据已绑定到文本块

<Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
            <TextBlock Text="{Binding Content}" Style="{ThemeResource BaseTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}">
            <TextBlock Text="{Binding Author}" FontWeight="Bold" HorizontalAlignment="Right" Margin="0,0,10,369" Height="56" VerticalAlignment="Bottom"></TextBlock>
</Grid>

我希望JSON文件中的部分内容为BOLD / UNDERLINE。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

<TextBlock Text="{Binding your_binding}" FontWeight="Bold" TextDecorations="Underline"></TextBlock>

答案 1 :(得分:0)

由于您只希望粗体内容的一部分使用RichTextBox。

<RichTextBox>
    <Paragraph>
        <Run Text="{Binding notBold}"></Run>
        <Run Text="{Binding bold}" FontWeight="Bold"></Run>
    </Paragraph>
</RichTextBox>

您可以编辑json结构或解析它并分配给逻辑中的正确对象。