Skip Navigation LinksHome / Tips / View Tip

How to style the caret in Silverlight 3

+ Add to SilverlightShow Favorites
1 comments   /   posted by Nikolay Raychev on Mar 25, 2009
(2 votes)
Categories: General
It's very easy to style the caret in Silverlight 3. Look at that huge TextBox with a caret in the rainbow colors:



You just need to set the CaretBrush property:

<TextBox FontSize="50" Width="100" Height="80">  
    <TextBox.RenderTransform> 
        <ScaleTransform ScaleX="6" ScaleY="1"/>  
    </TextBox.RenderTransform> 
    <TextBox.CaretBrush>
        <LinearGradientBrush x:Name="backgroundLinearGradientBrush"
            MappingMode="RelativeToBoundingBox"
                StartPoint="0,0" EndPoint="0,1">
            <LinearGradientBrush.GradientStops>
                <GradientStop Color="Red" Offset="0" />
                <GradientStop Color="Orange" Offset="0.167" />
                <GradientStop Color="Yellow" Offset="0.333" />
                <GradientStop Color="Green" Offset="0.5"/>
                <GradientStop Color="Blue" Offset="0.667" />
                <GradientStop Color="Indigo" Offset="0.833" />
                <GradientStop Color="Violet" Offset="1" />
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
    </TextBox.CaretBrush> 
</TextBox> 

You can use any Silverlight supported Brush.

Share


Comments

Comments RSS RSS
  • RE: How to style the caret in Silverlight 3  

    posted by apreski on Aug 24, 2009 15:33
    OMG what a wonderfull and perfect and so usefull tric ! i won't sleep for three days.

Add Comment

 
 

   
  
  
   
Please add 8 and 2 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)