Search code examples
c#wpfeffectglow

How to make a strong halo


I am able to put a halo around an UI element like a textbox. The problem is that it nearly is invisible. enter image description here

I do it with

Effect glowEffect = new DropShadowEffect
{
    BlurRadius = 20,
    Color = Colors.Gold,
    ShadowDepth = 10,
    Opacity = 1,
    RenderingBias = RenderingBias.Quality
};

and apply it with

tbxSearch.GotFocus += (sendGF, argGF) => { (sendGF as TextBox).Effect = glowEffect; };
tbxSearch.LostFocus += (sendLF, argLF) => { (sendLF as TextBox).Effect = null; };

I tried changing all the parameters but nearly nothing changed. Thanks


Solution

  • I have not found a better solution than:

    1. removing the UI element
    2. adding several UI element of the same type, same properties, same halo
    3. re-adding the UI element.

    That can also be done in a rountine.

    public void Add(TextBox tbx, int num)
    {
        var glowEffectRed = new DropShadowEffect
        {
            BlurRadius = 50,
            Color = new Color { A = 255, R = 255, G = 0, B = 0 },
            ShadowDepth = 0,
            Opacity = 1,
            RenderingBias = RenderingBias.Performance
        };
        tbx.Effect = glowEffectRed;
        var grd = (Grid)tbx.Parent;
        grd.Children.Remove(tbx);
        for (int iii = 0; iii < num; iii++)
        {
            var tbxAdd = new TextBox();
            tbxAdd.Effect = glowEffectRed;
            Grid.SetRow(tbxAdd, Grid.GetRow(tbx));
            tbxAdd.Height = tbx.ActualHeight;
            tbxAdd.Width = tbx.ActualWidth;
            grd.Children.Add(tbxAdd);   
        }
        grd.Children.Add(tbx);
    }
    

    and then called with the number of times the effect has to be re-applied

    Add(tbx1, 1);
    Add(tbx2, 5);
    Add(tbx3, 10);
    Add(tbx4, 15);
    

    enter image description here

    If used statically this might work. If the effect has to be dinamic this can surely lead to performance problems.