如何使用文本和不同字体的绑定定义文本块

How to define a textblock with a text and a binding with different font

我创建了一个包含硬编码文本和绑定文本的 TextBlock。

我希望绑定文本显示为 粗体 并且硬编码文本没有粗体。

<DataTemplate>
    <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
        <TextBlock Text="{Binding Vendor,  StringFormat='Vendor: {0}'}" FontWeight="Medium"/>
        <TextBlock Text="{Binding Model,  StringFormat='Brand: {0}'}" FontWeight="Medium"/>
        <TextBlock Text="{Binding Description,  StringFormat='Description: {0}'}" FontWeight="Medium"/>
        <TextBlock Text="{Binding Material,  StringFormat='Material: {0}'}" FontWeight="Medium"/>
        <TextBlock Text="{Binding Color,  StringFormat='Color: {0}'}" FontWeight="Medium"/>
        <TextBlock Text="{Binding Size,  StringFormat='Size: {0}'}" FontWeight="Medium" Visibility="{Binding SizeVisible}"/>
        <TextBlock Text="{Binding Price,  StringFormat='Price: {0}'}" FontWeight="Medium"/>
    </StackPanel>
</DataTemplate>

你可以制作两个内联 Run 块:

<TextBlock>
    <Run Text="Vendor:"/>
    <Run Text="{Binding Vendor, Mode=OneWay}" FontWeight="Bold"/>
</TextBlock>