2010-03-06 64 views
5

举例来说,如果我有一个标签:是否可以在Silverlight中为标签选择颜色?

Blah blah bladity blah

我想这个标签的前10%,使得字体颜色应该是红色的,其余的应该是绿色的。

这也许意味着它会着色B1和部分a。基本上像素明智的字体着色,而不是字符明智的。这是可能的,将如何完成?

回答

5

是的,这会是这样:

<Canvas> 
    <dataInput:Label Background="White" > 
    <dataInput:Label.Foreground> 
     <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> 
      <GradientStop Color="Red" Offset="0.1"/> 
      <GradientStop Color="Green" Offset="0.1"/> 
     </LinearGradientBrush> 
    </dataInput:Label.Foreground> 
    Blah blah bladity blah 
    </dataInput:Label> 
</Canvas> 

为了有渐变效果,你需要在两个Offset设置为相同的值。

注意:在这种字体大小(标准,没有任何改变),“B”和“l”是红色的,只有一小片“a”是。但Offset中的“0.1”意味着10%,所以您可以减小字体大小或更改Offset值。

+0

看起来我们都想出了相同的解决方案! – 2010-03-07 01:08:26

+0

+1好用的dataInput:标签控件。 – 2010-03-07 17:24:44

3

是的 - 你应该使用文本的前景颜色的渐变画笔。

<TextBlock Text="Blah blah bladity blah"> 
    <TextBlock.Foreground> 
     <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"> 
     <GradientStop Color="Red" Offset="0.1"/> 
     <GradientStop Color="Green" Offset="0.1"/> 
     </LinearGradientBrush> 
    </TextBlock.Foreground> 
</TextBlock> 
相关问题