5

テキストブロックのテキストの一部を太字にしたい。これは私が IValueConverter で試したものですが、うまくいかないようです。

public class Highlighter : IValueConverter
    {


        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }

            return "Question1:<Bold>Answer1</Bold>, Question2:<Bold>Answer2</Bold>, Question3:<Bold>Answer3</Bold>";

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

これは回答を太字にしません。

これは私がXAMLでそれを使用している方法です。

<TextBlock Height="Auto" Width="Auto" MaxHeight="64" Text="{Binding Path=QuestionAnswer, Mode=OneWay, Converter={x:Static Highlighter}}" />

テキストをフォーマットするか、TextBlock をコンバーターに送信することで、これを実現する方法はありますか?

4

2 に答える 2

2

ええ、このようなものはあなたを軌道に乗せるはずです。

<TextBlock>
   <Run Text="Question / Binding / Whatever..."/>
   <Run Text="Answer / Binding / Whatever..." FontWeight="Bold"/>
</TextBlock>
于 2012-12-27T17:45:57.480 に答える