私はいくつかのローカリゼーションを行っていますが、理解できないような問題にぶつかりました。
次のものを表示する必要があります: tcpCO₂( tcpはイタリック体)
<Italic>tcp</Italic> CO₂
HTMLを.resxファイルに入れるだけで、すべてが結婚するだろうと思っていましたが、出力の内容には、括弧などを含むhtmlが表示されます。この問題について誰かが入力を持っていますか?
私はいくつかのローカリゼーションを行っていますが、理解できないような問題にぶつかりました。
次のものを表示する必要があります: tcpCO₂( tcpはイタリック体)
<Italic>tcp</Italic> CO₂
HTMLを.resxファイルに入れるだけで、すべてが結婚するだろうと思っていましたが、出力の内容には、括弧などを含むhtmlが表示されます。この問題について誰かが入力を持っていますか?
添付の動作を使用して、リッチ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
ただし、あなたの場合は、のキャプションテンプレートにあるため、直接アクセスすることはできませんLayoutPanel
。TextBlock
したがって、このテンプレートを再定義して、 :に動作を適用する必要があります。
<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>