如何将彩色文本添加到<system:string>?

时间:2019-07-05 03:48:40

标签: wpf xaml

我正在用一堆system:string创建一个资源字典,我可以用DynamicResource调用它。我试图用不同的颜色突出显示字符串中的某些文本,这样我就不需要做太多的“运行文本”

<ResourceDictionary              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib">

<Image.ToolTip>
   <ToolTip BorderBrush="LightGoldenrodYellow" BorderThickness="1" Background="Black">
       <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="LightGoldenrodYellow" FontSize="14" FontWeight="Bold">
            <Run Text="{DynamicResource Example}"/>
            <Run Text="{DynamicResource Example1}" FontStyle="Italic" FontSize="12" FontWeight="Normal"/>
       </TextBlock>
   </ToolTip>
</Image.ToolTip>

 <s:String x:Key="Example" xml:space="preserve">Lucky Dice</s:String>
 <s:String x:Key="Example1" xml:space="preserve">&#10;Has a 30% chance to get an extra item.</s:String>
</ResourceDictionary>

<s:String x:Key="Example" xml:space="preserve">&#10;Has a <Font color=red>30%</font> chance to get an extra item.</s:String>

0 个答案:

没有答案