Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply stroke to textblock in XAML

I have a Silverlight app where I want to give my textblock an outline (not the textblock, the characters themselves), otherwise known as stroke.

I found this question which works for WPF, but is there a way to accomplish this when working with XAML/Silverlight (PresentationFramework is not a Silverlight assembly)? Is there an existing implementation?

like image 536
tnw Avatar asked Jul 24 '13 13:07

tnw


People also ask

Can we edit TextBlock in WPF?

TextBlock is not editable. Use TextBox instead. Save this answer.

How do I create a line break in TextBlock WPF?

Adding Line Breaks You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element. If you have configured the text to be justified, the final line before the line break will not be expanded to fill the available width.

What is TextBlock in XAML?

TextBlock is the primary control for displaying read-only text in apps.

What is the difference between label and TextBlock in WPF?

Labels usually support single line text output while the TextBlock is intended for multiline text display. For example in wpf TextBlock has a property TextWrapping which enables multiline input; Label does not have this.


1 Answers

Going with @Chris W. idea, I came up with this code, although not the finest solution, it works:

<StackPanel>

    <!-- With DropShadow -->
    <TextBlock Foreground="#FFFF0000" Text="With DropShadow" FontSize="16">
        <TextBlock.Effect>
            <DropShadowEffect ShadowDepth="0" BlurRadius="1" Color="#FF000000" />
        </TextBlock.Effect>
    </TextBlock>

     <!-- No DropShadow -->
    <TextBlock Foreground="#FFFF0000" Text="No DropShadow" FontSize="16" />

</StackPanel>
like image 192
Tico Avatar answered Oct 17 '22 01:10

Tico