Linked Questions

Popular Questions

I would like to understand how you can create such an effect, in which the text in the TextBlock / RichTextBlock elements will glow like neon, or at least just glow. To achieve this effect, I need to stroke the text and also give it a colored shadow. I never figured out how to create a text stroke, but I succeeded with a shadow. At the moment my code looks something like this:

var compositor = ElementCompositionPreview.GetElementVisual(Host).Compositor;

var dropShadow = compositor.CreateDropShadow();
dropShadow.Color = Colors.Red;
dropShadow.BlurRadius = 3;
dropShadow.Opacity = 1;
dropShadow.Mask = TextBlock.GetAlphaMask();

var spriteVisual = compositor.CreateSpriteVisual();
spriteVisual.Size = Host.ActualSize;
spriteVisual.Shadow = dropShadow;

ElementCompositionPreview.SetElementChildVisual(Host, spriteVisual);

But the shadow is honestly very weak and does not create a glow effect, even if I apply as many as 5 layers with a shadow. Perhaps it's the overlay of colors and they do not sum up properly. Please tell me how I can improve the effect. Can I still stroke the text and how do I make the shadow brighter. Or maybe there is even a more efficient and correct way to create a glow effect. I would be very happy if this exists. Thank you in advance for your help!

UPDATE

Issue resolved. I'll write the solution here for those who might also need it.

I created a custom control by this manual but changed the code of the MakeShadow() method like this

private void MakeShadow()
{
    var compositor = ElementCompositionPreview.GetElementVisual(Host).Compositor;

    for (float i = 1; i <= 5; i++)
    {
        ((ContainerVisual)ElementCompositionPreview.GetElementVisual(Host)).Children.InsertAtBottom(GetSpriteVisual(compositor, i));
    }


    SpriteVisual GetSpriteVisual(Compositor compositor, float radius)
    {
        var dropShadow = compositor.CreateDropShadow();
        dropShadow.Color = Color.FromArgb(250, 140, 240, 250);
        dropShadow.BlurRadius = radius;
        dropShadow.Opacity = 1;
        dropShadow.Mask = TextBlock.GetAlphaMask();

        var spriteVisual = compositor.CreateSpriteVisual();
        spriteVisual.Size = Host.ActualSize;
        spriteVisual.Shadow = dropShadow;

        return spriteVisual;
    }
}

Here in the loop, the value of i is the number of times the shadow effect will be applied. The higher it is, the more intense the text will glow.

Related Questions