0

私はいくつかのローカリゼーションを行っていますが、理解できないような問題にぶつかりました。

次のものを表示する必要があります: tcpCO₂( tcpはイタリック体)

<Italic>tcp</Italic> CO₂

HTMLを.resxファイルに入れるだけで、すべてが結婚するだろうと思っていましたが、出力の内容には、括弧などを含むhtmlが表示されます。この問題について誰かが入力を持っていますか?

4

1 に答える 1

1

添付の動作を使用して、リッチXAMLテキストをTextBlock:で表示します。

public static class TextBlockBehavior
{
    [AttachedPropertyBrowsableForType(typeof(TextBlock))]
    public static string GetRichText(TextBlock textBlock)
    {
        return (string)textBlock.GetValue(RichTextProperty);
    }

    public static void SetRichText(TextBlock textBlock, string value)
    {
        textBlock.SetValue(RichTextProperty, value);
    }

    public static readonly DependencyProperty RichTextProperty =
        DependencyProperty.RegisterAttached(
          "RichText",
          typeof(string),
          typeof(TextBlockBehavior),
          new UIPropertyMetadata(
            null,
            RichTextChanged));

    private static void RichTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
    {
        TextBlock textBlock = o as TextBlock;
        if (textBlock == null)
            return;

        var newValue = (string)e.NewValue;

        textBlock.Inlines.Clear();
        if (newValue != null)
            AddRichText(textBlock, newValue);
    }

    private static void AddRichText(TextBlock textBlock, string richText)
    {
        string xaml = string.Format(@"<Span>{0}</Span>", richText);
        ParserContext context = new ParserContext();
        context.XmlnsDictionary.Add(string.Empty, "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
        var content = (Span)XamlReader.Parse(xaml, context);
        textBlock.Inlines.Add(content);
    }
}

次のように使用できます。

<TextBlock bhv:TextBlockBehavior.RichText="{x:Static Resources:Resource.CO2}">

TextBlockただし、あなたの場合は、のキャプションテンプレートにあるため、直接アクセスすることはできませんLayoutPanelTextBlockしたがって、このテンプレートを再定義して、 :に動作を適用する必要があります。

<dxdo:LayoutPanel Name="PanelCo2" Caption="{x:Static Resources:Resource.CO2}">
    <dxdo:LayoutPanel.CaptionTemplate>
        <DataTemplate>
            <TextBlock bhv:TextBlockBehavior.RichText="{Binding}">
        </DataTemplate>
    </dxdo:LayoutPanel.CaptionTemplate>
</dxdo:LayoutPanel>
于 2012-05-09T16:33:58.747 に答える